Recursive Java solution


  • 0
    A
    public class Solution {
        int val;
        int lev;
        public int findBottomLeftValue(TreeNode root) {
            val = root.val;
            lev = 0;
            helper(root, 0);
            return val;
        }
            
        private void helper(TreeNode root, int level) {
            if (root==null) return;
            if (root.left==null && root.right==null && level>lev) {
                val = root.val;
                lev=level;
                return;
            }
            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.