Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Leetcode/Pathsum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ class Solution {
return false;
}
pres_sum+=root->val;
if(root->left == NULL and root->right == NULL){
if(root->left == NULL && root->right == NULL){
return pres_sum == targetSum;
}
return havingPathSum(root->left,targetSum,pres_sum) || havingPathSum(root->right,targetSum,pres_sum);
}
bool hasPathSum(TreeNode* root, int targetSum) {
if(root == NULL){
return false;
}
return havingPathSum(root,targetSum,0);

}
Expand Down