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

  

相关文章:

  • 2022-12-23
  • 2021-08-25
  • 2022-01-18
  • 2022-02-28
  • 2021-09-02
  • 2021-07-26
猜你喜欢
  • 2021-10-19
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2021-04-01
  • 2021-11-07
  • 2021-12-15
相关资源
相似解决方案