Skip to content

Commit 8c9696a

Browse files
committed
112
1 parent f177e91 commit 8c9696a

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

112.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
bool hasPathSum(TreeNode* root, int sum) {
4+
vector<int>A;
5+
int value=0;
6+
tosearch(root,value,A);
7+
int jj=A.size();
8+
for(int i=0;i<jj;i++){
9+
if(A[i]==sum){
10+
return 1;
11+
}
12+
}
13+
return 0;
14+
}
15+
void tosearch(TreeNode * root ,int value, vector<int>&A){
16+
if(root==NULL){
17+
return ;
18+
}
19+
value=value+root->val;
20+
if(root->left==NULL && root->right==NULL){
21+
A.push_back(value);
22+
return ;
23+
}
24+
tosearch(root->left,value,A) ;
25+
tosearch(root->right,value,A);
26+
return ;
27+
}
28+
};

0 commit comments

Comments
 (0)