Java DFS Solution


  • 0
    M
    Integer leftMostValue = 0;
        Integer level = Integer.MIN_VALUE;
        
        public int findBottomLeftValue(TreeNode root) {
            findBottomLeftValueUtil(root, 0);
            return this.leftMostValue;
        }
        
        public void findBottomLeftValueUtil(TreeNode root, int l) {
            
            if (root == null) {
                return;
            }
            
            findBottomLeftValueUtil(root.left, l+1);        
            if (l > this.level) {
                this.level = l;
                this.leftMostValue = root.val;
            }
            
            findBottomLeftValueUtil(root.right, l+1);
            if (l > this.level) {
                this.level = l;
                this.leftMostValue = root.val;
            }
        }
    

Log in to reply
 

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