每日一题 429. N 叉树的层序遍历
429. N 叉树的层序遍历
/*
class Solution {
public:
vector<vector<int>> levelOrder(Node* root) {
queue<Node*> que;
que.push(root);
vector<vector<int>> ans;
if(root == nullptr)
{
return ans;
}
while(!que.empty())
{
int sizeQue = que.size();
vector<int> cur;
for(int i=0;i<sizeQue;++i)
{
auto t = que.front();
que.pop();
cur.push_back(t->val);
for(auto e : t->children)
{
if(e != nullptr)
{
que.push(e);
}
}
}
ans.push_back(cur);
}
return ans;
}
};