Skip to content

Latest commit

 

History

History
19 lines (17 loc) · 498 Bytes

107.md

File metadata and controls

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

class Solution:
    def levelOrderBottom(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[::-1]