-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPath Sum II.cpp
More file actions
31 lines (27 loc) · 788 Bytes
/
Copy pathPath Sum II.cpp
File metadata and controls
31 lines (27 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<vector<int>> res;
vector<vector<int>> pathSum(TreeNode* root, int sum) {
vector<int> path;
return res;
}
void findpath(TreeNode* root, int sum, vector<int> & path){
if(root == NULL || sum < 0) return;
if(root->left == NULL && root->right == NULL&& root->val == sum)
res.push_back(path);
path.push_back(root);
findpath(root->left, sum - root->val, path);
findpath(root->right, sum - root->val, path);
path.pop();
return;
}
};