-
-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
路径总和 #296
Comments
/**
* @param {TreeNode} root
* @param {number} targetSum
* @return {boolean}
*/
var hasPathSum = function(root, targetSum) {
function backtracking(root,sum){ //回溯
if(sum === 0 && !root.left && !root.right){
return true;
}
if(!root.left && !root.right) return false;
if(root.left && backtracking(root.left,sum - root.left.val)) return true;
if(root.right && backtracking(root.right,sum - root.right.val)) return true;
return false;
}
if(!root) return false;
return backtracking(root,targetSum - root.val);
}; |
`var hasPathSum = function(root, targetSum) { var helper = function(root, pathSum, target) {
}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: