-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path[113]_Path_Sum_II.cpp
More file actions
44 lines (41 loc) · 955 Bytes
/
[113]_Path_Sum_II.cpp
File metadata and controls
44 lines (41 loc) · 955 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
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <vector>
using namespace std;
//https://leetcode.com/problems/path-sum-ii/
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution {
public:
vector<vector<int>> ans;
void dfs(TreeNode* root,vector<int> &v,int sum,int target){
if(root==NULL) return;
if(target==sum&&root->left==NULL&&root->right==NULL){
ans.push_back(v);
}
sum+=root->val;
v.push_back(root->val);
dfs(root->left,v,sum,target);
dfs(root->right,v,sum,target);
v.pop_back();
}
vector<vector<int>> pathSum(TreeNode* root, int sum) {
vector<int> v;
dfs(root,v,0,sum);
return ans;
}
};
void .asmf(vector<int> v){
v.push_back(4);
}
int main(){
vector<int> v={1,2,3};
f(v);
for(int item:v){
cout<<item<<" ";
}
return 0;
}