问题 ​​https://leetcode-cn.com/problems/path-sum/​

练习使用JavaScript解答

/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @param {number} sum
* @return {boolean}
*/
var hasPathSum = function(root, sum) {
if(!root)
return false;
if(!root.left && !root.right)
return sum == root.val;
return arguments.callee(root.left, sum - root.val) || arguments.callee(root.right, sum - root.val);
};