标签:tco ret leetcode python tree append and bfs code
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
Leetcode 429. N-ary Tree Level Order Traversal
标签:tco ret leetcode python tree append and bfs code
原文地址:https://www.cnblogs.com/zywscq/p/10743417.html