题目:
题解:
class Solution:
def levelOrder(self, root: 'Node') -> List[List[int]]:
if not root:
return []
ans = list()
q = deque([root])
while q:
cnt = len(q)
level = list()
for _ in range(cnt):
cur = q.popleft()
level.append(cur.val)
for child in cur.children:
q.append(child)
ans.append(level)
return ans