We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d1468d2 commit 725a5a5Copy full SHA for 725a5a5
August-LeetCoding-Challenge/08-Path-Sum-III/Path-Sum-III.cpp
@@ -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