-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path257.cpp
34 lines (31 loc) · 810 Bytes
/
257.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
class Solution {
public:
vector<string> binaryTreePaths(TreeNode* root) {
vector<string>ss;
string str2="";
treepath(root,ss,str2);
return ss;
}
void treepath(TreeNode * root,vector<string>&ss,string str2){
if(root==NULL){
return ;
}
int a= root->val;
string str=to_string(a);
if(root->left!=NULL || root->right!=NULL)
{
str2=str2+str+"->";
}
if(root->left==NULL && root->right==NULL)
{
str2=str2+str;
}
if(root->left==NULL && root->right==NULL){
ss.push_back(str2);
return ;
}
treepath(root->left,ss,str2);
treepath(root->right,ss,str2);
return ;
}
};