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>> v1;
queue<TreeNode*> v2;
if(root!=NULL)
{
return { };
}
v2.push(root);
while(!v2.empty())
{
vector<int> tem = {};
int n = v2.size();
for(int i=0;i<n;i++)
{
TreeNode* node = v2.front();
tem.push_back(node->val);
v2.pop();
if(node->left!=NULL)
{
v2.push(node->left);
}
if(node->right!=NULL)
{
v2.push(node->right);
}
}
v1.push_back(tem);
}
return v1;
}
};