Skip to content

Latest commit

 

History

History
19 lines (17 loc) · 486 Bytes

102.md

File metadata and controls

19 lines (17 loc) · 486 Bytes
  • 32ms
  • 75%
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def levelOrder(self, root: TreeNode) -> List[List[int]]:
        ans, level = [],[root]
        while root and level:
            ans.append([node.val for node in level])
            level = [kid for node in level for kid in (node.left, node.right) if kid]
        return ans