My Java Solution


  • 0
    S
    public class Solution {
        int[] res = new int[2];
        public int findBottomLeftValue(TreeNode root) {
            res[0] = 1;
            res[1] = root.val;
            helper(root, 1);
            return res[1];
        }
        
        private void helper(TreeNode root, int level){
            if(root.right != null){
                if(level >= res[0]){
                    res[0] = level;
                    res[1] = root.right.val;
                }
                helper(root.right, level + 1);
            }
            if(root.left != null){
                if(level >= res[0]){
                    res[0] = level;
                    res[1] = root.left.val;
                }
                helper(root.left, level + 1);
            }
            return;
        }
    }
    

  • 0
    Y
    This post is deleted!

  • 0
    S

    Thanks, the time is 11ms.


Log in to reply
 

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