Skip to content

Commit 725a5a5

Browse files
authored
Create Path-Sum-III.cpp
1 parent d1468d2 commit 725a5a5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int cpt = 0;
4+
int pathSum(TreeNode* root, int sum) {
5+
recur(root, sum);
6+
return cpt;
7+
}
8+
void recur(TreeNode* root, int sum, bool isConsecutive = false){
9+
if(!root) return;
10+
if(sum == root->val) ++cpt;
11+
recur(root->left, sum - root->val, true);
12+
recur(root->right, sum - root->val, true);
13+
if(!isConsecutive){
14+
recur(root->left, sum, false);
15+
recur(root->right, sum, false);
16+
}
17+
}
18+
};

0 commit comments

Comments
 (0)