-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path129.cpp
More file actions
29 lines (26 loc) · 728 Bytes
/
Copy path129.cpp
File metadata and controls
29 lines (26 loc) · 728 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
class Solution {
public:
int sumNumbers(TreeNode* root) {
if(root==NULL){
return 0;
}
vector<int>A;
findingsolution(root,A,0);
int sum=0;
for(int i=0;i<A.size();i++){
cout<<A[i]<<endl;
sum=sum+A[i];
}
return sum;
}
void findingsolution(TreeNode* root,vector<int>&A,int value){
if(root->left==NULL && root->right==NULL){
A.push_back(value*10 + root->val);
return ;
}
value=(value)*10 + root->val ;
if(root->left) findingsolution(root->left,A,value);
if(root->right) findingsolution(root->right,A,value);
return ;
}
} ;