-
Notifications
You must be signed in to change notification settings - Fork 1
/
107(b).cpp
46 lines (36 loc) · 956 Bytes
/
107(b).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
35
36
37
38
39
40
41
42
43
44
45
46
class Solution {
public:
vector<vector<int>> levelOrderBottom(TreeNode* root) {
vector<vector<int>>A;
if(root==NULL)
{
return A;
}
queue<TreeNode *>q;
q.push(root);
// vector<int>B;
while(!q.empty())
{
int sz=q.size();
vector<int>B;
while(sz--){
TreeNode * node=q.front();
q.pop();
B.push_back(node->val);
if(node->left){
q.push(node->left);
}
if(node->right){
q.push(node->right);
}
}
A.push_back(B);
}
vector<vector<int>>C;
for(int i=(A.size()-1);i>=0;i--)
{
C.push_back(A[i]);
}
return C;
}
};