Find Bottom Left Tree Value - Python Easy Answer Yet Seems Not Slow


  • 0
    A

    Definition for a binary tree node.

    class TreeNode(object):

    def init(self, x):

    self.val = x

    self.left = None

    self.right = None

    class Solution(object):
    def findBottomLeftValue(self, root):
    """
    :type root: TreeNode
    :rtype: int
    """
    list1 = [root]
    while 1:
    list2 = []
    for i in list1:
    if i.left: list2.append(i.left)
    if i.right: list2.append(i.right)
    if not list2: break
    list1 = list2
    return list1[0].val


Log in to reply
 

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