题目要求:
题目来源:力扣
class Solution {
public:
vector> levelOrder(TreeNode* root) {
if(root == nullptr)
{
return vector> ();
}
queue q;
int levelsize = 1;
q.push(root);
vector> vv;
while(!q.empty())
{
vector v;
for(int i = 0;i < levelsize;i++)
{
TreeNode* front = q.front();
q.pop();
v.push_back(front->val);
if(front->left)
q.push(front->left);
if(front->right)
q.push(front->right);
}
vv.push_back(v);
levelsize = q.size();
}
return vv;
}
};



