Java Solution with preorder dfs / T : O(N), S : O(1)


  • 0
    J
    int gDepth = -1;
        int val = 0;
        
        public int findBottomLeftValue(TreeNode root) {
            preOrderDFS(root, 0);
            return val;
        }
        
        public void preOrderDFS(TreeNode root, int depth){
            if(root == null)
                return;
            
            if(depth > gDepth){
                gDepth = depth;
                val = root.val;
            }
            
            preOrderDFS(root.left, depth+1);
            preOrderDFS(root.right, depth+1);
        }
    

Log in to reply
 

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