Python BFS solution


  • 0
    Y

    Use deque to store nodes

    from collections import deque
    
    class Solution(object):
        def findBottomLeftValue(self, root):
            """
            :type root: TreeNode
            :rtype: int
            """
            queue = deque([root])
            node = None
            while queue:
                node = queue.popleft()
                if node.right:
                    queue.append(node.right)
                if node.left:
                    queue.append(node.left)
            return node.val
    

Log in to reply
 

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