DFS Java solution


  • 0
    public class Solution {
        private int res = 0;
        private int maxDepth = -1;
        public int findBottomLeftValue(TreeNode root) {
            helper(root, 0);
            return res;
        }
        private void helper(TreeNode root, int depth) {
            if (root == null) return;
            if (depth > maxDepth) {
                res = root.val;
                maxDepth = depth;
            }
            helper(root.left, depth + 1);
            helper(root.right, depth + 1);
        }
    }
    

Log in to reply
 

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