429. N-ary Tree Level Order Traversal
https://leetcode.com/problems/n-ary-tree-level-order-traversal/
Python
DFS
class Solution:
def levelOrder(self, root: 'Node') -> List[List[int]]:
def dfs(node, level, result):
if not node:
return
if len(result) <= level:
result.append([])
result[level].append(node.val)
for child in node.children:
dfs(child, level+1, result)
levels = []
dfs(root, 0, levels)
return levels