7ms Straightforward Java Solution


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

Log in to reply
 

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