Iterative 4 line Python Solution


  • 0
    A

    Perform a level-order traversal using list comprehension.

    class Solution(object):
        def findBottomLeftValue(self, root):
            """
            :type root: TreeNode
            :rtype: int
            """
            currLevel = [root]
            while any([item.left for item in currLevel if item.left] + [item.right for item in currLevel if item.right]):
                currLevel = [item.left for item in currLevel if item.left] + [item.right for item in currLevel if item.right]
            return currLevel[0].val
    

Log in to reply
 

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