-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLC_107.cpp
41 lines (41 loc) · 1023 Bytes
/
LC_107.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
/**
* 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 {
public:
vector<vector<int>> levelOrderBottom(TreeNode* root) {
vector<vector<int>>v;
queue< TreeNode* >q;
int count,i;
//map<int, vector<int> >mp;
if(root==NULL)
return v;
q.push(root);
while(!q.empty())
{
count=q.size();
vector<int>temp;
while(count>0)
{
TreeNode *x=q.front();
q.pop();
temp.push_back(x->val);
// mp[depth].push_back(x->val);
if(x->left)
q.push(x->left);
if(x->right)
q.push(x->right);
count--;
}
v.push_back(temp);
}
reverse(v.begin(),v.end());
return v;
}
};