/**
* 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>> levelOrder(TreeNode* root) {
vector<vector<int>> vv;
vector<int>v;
if(root == NULL) return vv;
int h0=1;
int h1;
TreeNode* temp;
queue<TreeNode*> q;
q.push(root);
while(!q.empty()){
h1=0;
while(h0--){
temp=q.front();
q.pop();
v.push_back(temp->val);
if(temp->left) {q.push(temp->left);h1++;}
if(temp->right) {q.push(temp->right);h1++;}
}
vv.push_back(v);
v.clear();
h0=h1;
}
return vv;
}
};