My accepted Python solution


  • 0
    J
    class Solution(object):
        def levelOrderBottom(self, root):
            """
            :type root: TreeNode
            :rtype: List[List[int]]
            """
            if not root:
                return []
            level,result = [root],[]
            while level: # iterate all levels until empty
                result.append([n.val for n in level])
                level = [kid for n in level for kid in (n.left,n.right) if kid]
            result.reverse()
            return result
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.