Given the root of a binary tree, return the leftmost value in the last row of the tree.

&nbsp;
Example 1:

Input: root = [2,1,3]
Output: 1


Example 2:

Input: root = [1,2,3,4,null,5,6,null,null,7]
Output: 7


&nbsp;
Constraints:


	The number of nodes in the tree is in the range [1, 104].
	-231 &lt;= Node.val &lt;= 231 - 1


# 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
class Solution:
    def findBottomLeftValue(self, root: Optional[TreeNode]) -> int:
        
        res = root.val
        stack = [(0, root)]
        prev_d = 0
        
        while stack:
            
            curr_d, curr_v = stack.pop(0)
            
            if curr_v.left:
                stack.append((curr_d+1, curr_v.left))
                if prev_d != curr_d + 1:
                    res = curr_v.left.val
                    prev_d = curr_d+1
            
            if curr_v.right:
                stack.append((curr_d+1, curr_v.right))
                if prev_d != curr_d + 1:
                    res = curr_v.right.val
                    prev_d = curr_d+1
        
        return res
		
		# An Upvote will be encouraging
class Solution {
    int max = Integer.MIN_VALUE;
    int res = -1;
    public int findBottomLeftValue(TreeNode root) {
        check(root,0);
        return res;
    }
    void check(TreeNode root, int h){
        if(root==null)
            return;
        if(h>max){
            max=h;
            res = root.val;
        }
        check(root.left,h+1);
        check(root.right,h+1);
    }
}
class Solution {
public:
    int findBottomLeftValue(TreeNode* root) {
        queue<TreeNode*> q;
        q.push(root);
        int ans=root->val;
        
        while(!q.empty()){
            int n=q.size();
            for(int i=0;i<n;i++){
                TreeNode* curr= q.front();
                q.pop();
                
                if(i==0) ans=curr->val;
                
                if(curr->left) q.push(curr->left);
                if(curr->right) q.push(curr->right);
            }
        }
        return ans;
    }
};
var findBottomLeftValue = function(root) {
    let arr=[];
    let q=[root];
    while(q.length!==0){
        let current=q.shift();
        arr.push(current.val)
        if(current.right){
            q.push(current.right)
        }
        if(current.left){
            q.push(current.left);
        }
    }
    return arr[arr.length-1]
};
Find Bottom Left Tree Value