# Definition for a binary tree node.
class TreeNode:
     def __init__(self, x):
         self.val = x
         self.left = None
         self.right = None

class Solution:
    def findBottomLeftValue(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        if root==None:
            return
        line1,line2=[],[]
        line1.append(root)
        while line1 or line2:
            temp = line1[0].val
            for item in line1:
                if item.left:
                    line2.append(item.left)
                if item.right:
                    line2.append(item.right)
            if line2==[]:
                return temp
            line1=line2.copy()
            line2.clear()
s=Solution()
root=TreeNode(1)
root.left=TreeNode(3)
root.right=TreeNode(2)
root.left.left=TreeNode(5)
root.left.right=TreeNode(3)
root.right.right=TreeNode(9)
root.right.right.left=TreeNode(7)
print(s.findBottomLeftValue(root))