Skip to content

Commit 100bb31

Browse files
authored
Merge pull request gzc426#309 from wswdwf/patch-13
Create Sagittarius.md
2 parents 1146dad + 7f0621c commit 100bb31

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

2018.12.10-leetcode107/Sagittarius.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
```
2+
/**
3+
* Definition for a binary tree node.
4+
* struct TreeNode {
5+
* int val;
6+
* TreeNode *left;
7+
* TreeNode *right;
8+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
9+
* };
10+
*/
11+
class Solution {
12+
public:
13+
vector<vector<int>> a;
14+
vector<vector<int>> levelOrderBottom(TreeNode* root) {
15+
if(!root)
16+
return a;
17+
18+
lot(root,0);
19+
for(int i=0;i<a.size()/2;i++)
20+
{
21+
vector<int> v1;
22+
v1=a[i];
23+
a[i]=a[a.size()-1-i];
24+
a[a.size()-1-i]=v1;
25+
}
26+
return a;
27+
}
28+
void lot(TreeNode* node,int level)
29+
{
30+
if(a.size()<level+1)
31+
{
32+
vector<int> v1;
33+
v1.push_back(node->val);
34+
a.push_back(v1);
35+
}
36+
else
37+
a[level].push_back(node->val);
38+
39+
if(node->left)
40+
lot(node->left,level+1);
41+
if(node->right)
42+
lot(node->right,level+1);
43+
}
44+
};
45+
```

0 commit comments

Comments
 (0)