/**
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
class Solution {
public:
/**
*
* @param root TreeNode类
* @return int整型vector<vector<>>
*/
vector<vector<int> > levelOrder(TreeNode* root) {
// write code here
vector<vector<int>>res;
if(!root)return res;
queue<TreeNode*>q;
q.push(root);
while(!q.empty()){
vector<int>subres;
int count = q.size();
while(count--){
TreeNode* temp = q.front();
subres.push_back(temp->val);
q.pop();
if(temp->left){
q.push(temp->left);
}
if(temp -> right){
q.push(temp->right);
}
}
if(subres.size() > 0){
res.push_back(subres);
}
}
return res;
}
};