---
# System prepended metadata

title: 0429. N-ary Tree Level Order Traversal
tags: [Leetcode, Tree, Medium]

---

# 0429. N-ary Tree Level Order Traversal
###### tags: `Leetcode` `Medium` `Tree`
Link: https://leetcode.com/problems/n-ary-tree-level-order-traversal/
## 思路
层序遍历
## Code
```java=
class Solution {
    public List<List<Integer>> levelOrder(Node root) {
        List<List<Integer>> ans = new ArrayList<>();
        if(root==null) return ans;
        Queue<Node> q = new LinkedList<>();
        q.add(root);
        while(!q.isEmpty()){
            int size = q.size();
            List<Integer> currLevel = new ArrayList<>();
            for(int i=0; i<size; i++){
                Node curr = q.poll();
                currLevel.add(curr.val);
                if(curr.children!=null){
                   q.addAll(curr.children); 
                }
            }
            ans.add(currLevel);
        }
        return ans;
    }
}
```