Skip to content

Commit 2143bb0

Browse files
committedFeb 21, 2020
107
1 parent 50459aa commit 2143bb0

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
 

‎107.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
class Solution {
2+
public:
3+
vector<vector<int>> levelOrderBottom(TreeNode* root) {
4+
5+
vector<vector<int>>A;
6+
7+
if(root==NULL)
8+
{
9+
return A;
10+
}
11+
12+
queue<TreeNode *>q;
13+
q.push(root);
14+
// vector<int>B;
15+
while(!q.empty())
16+
{
17+
int sz=q.size();
18+
vector<int>B;
19+
while(sz--){
20+
21+
TreeNode * node=q.front();
22+
q.pop();
23+
B.push_back(node->val);
24+
if(node->left){
25+
q.push(node->left);
26+
}
27+
if(node->right){
28+
q.push(node->right);
29+
}
30+
}
31+
A.push_back(B);
32+
}
33+
vector<vector<int>>C;
34+
35+
for(int i=(A.size()-1);i>=0;i--)
36+
{
37+
C.push_back(A[i]);
38+
}
39+
40+
41+
return C;
42+
43+
44+
45+
}
46+
};

0 commit comments

Comments
 (0)