-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.cpp
More file actions
39 lines (37 loc) · 843 Bytes
/
program.cpp
File metadata and controls
39 lines (37 loc) · 843 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
#include "../include/pre.h"
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
string cur;
vector<string> rst;
bool helper(TreeNode* t) //return is_null
{
if (t == NULL) return true;
auto tmp = cur;
if (cur.size() != 0) cur += "->";
cur += to_string(t->val);
bool r = helper(t->left);
r = helper(t->right) && r;
if (r && cur.size() != 0) rst.push_back(cur);
cur = tmp;
return false;
}
public:
vector<string> binaryTreePaths(TreeNode* root) {
rst = decltype(rst)();
cur = decltype(cur)();
helper(root);
return rst;
}
};
int main()
{
return 0;
}