forked from Masked-coder11/gfg-POTD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
22.01.2024.cpp
41 lines (33 loc) · 816 Bytes
/
22.01.2024.cpp
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
//User function Template for C++
/*// A Tree node
struct Node
{
int key;
struct Node *left, *right;
};*/
class Solution
{
public:
void solve(Node* root, int curr, int target, vector<int>path, vector<vector<int>>&ans){
if(!root){
return;
}
curr+=root->key;
path.push_back(root->key);
if(curr==target){
ans.push_back(path);
}
solve(root->left, curr, target, path, ans);
solve(root->right, curr, target, path, ans);
return;
}
vector<vector<int>> printPaths(Node *root, int sum)
{
//code here
vector<vector<int>>ans;
vector<int>path;
int curr=0;
solve(root, curr, sum, path, ans);
return ans;
}
};