bfs
class Solution: def levelOrder(self, root: 'Node') -> List[List[int]]: q,ans=[root],[] while q and q[0]: ans.append([node.val for node in q]) q=[child for node in q for child in node.children if child] return ans
bfs
class Solution: def levelOrder(self, root: 'Node') -> List[List[int]]: q,ans=[root],[] while q and q[0]: ans.append([node.val for node in q]) q=[child for node in q for child in node.children if child] return ans