Simple solution.


  • 1
    class Solution {
        public int findBottomLeftValue(TreeNode root) {
            return depthSearch(root, 0)[0];
        }
        
        public int[] depthSearch(TreeNode root, int depth){
            int[] left = {root.val, depth};
            int[] right = {root.val, depth};
            if(root.left != null) left = depthSearch(root.left, depth+1);
            if(root.right != null) right = depthSearch(root.right, depth+1);
            
            if(left[1] >= right[1]){
                return left;
            }else{
                return right;
            }
        }
    }
    

Log in to reply
 

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