Clean JAVA In-Order DFS solution


  • 0
    W
    public class Solution {
        private int level = -1;
        private int val = 0;
        
        public int findBottomLeftValue(TreeNode root) {
            dfs(root, 0);
            return val;
        }
        private void dfs(TreeNode root, int lv) {
            if (root == null) return;
            dfs(root.left, lv + 1);
            if (lv > level) {
                val = root.val;
                level = lv;
            }
            dfs(root.right, lv + 1);
        }
    }
    

Log in to reply
 

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