forked from grantrostig/cpp_by_example
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
43 lines (37 loc) · 859 Bytes
/
main.cpp
File metadata and controls
43 lines (37 loc) · 859 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
40
41
42
43
/* I didn't write this, not sure why I have it in my repo. */
#include <iostream>
using namespace std;
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution {
public:
string result {};
string tree2str(TreeNode* t) {
if (t == nullptr) return string {};
result = std::to_string(t->val)
+ "("+tree2str(t->left)
+ tree2str(t->right)+")";
return result;
}
};
int main()
{
Solution s;
TreeNode t {5};
auto answer = s.tree2str( &t);
cout << "Hello World!" << endl;
return 0;
}