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


from collections import deque


class Solution:
    def findBottomLeftValue(self, root: TreeNode) -> int:
        q = deque()
        q.append(root)
        while q:
            level = []
            for _ in range(len(q)):
                root = q.popleft()
                level.append(root.val)
                if root.left:
                    q.append(root.left)
                if root.right:
                    q.append(root.right)
            if level:
                leftmost = level[0]
        return leftmost
