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
作者:LeetCode-Solution
链接:https://leetcode.cn/problems/n-ary-tree-level-order-traversal/solution/n-cha-shu-de-ceng-xu-bian-li-by-leetcode-lxdr/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
程序员小白条:建议换下项目,智能 AI 旅游推荐平台:https://github.com/luoye6/vue3_tourism_frontend
智能 AI 校园二手交易平台:https://github.com/luoye6/vue3_trade_frontend
GPT 智能图书馆:https://github.com/luoye6/Vue_BookManageSystem
选项目要选自己能掌握的,然后最好能自己拓展的,分布式这种尽量别去写,不然你只能背八股文了,另外实习的话要多投,尤其是学历不利的情况下,多找几段实习,最好公司title大一点的