My simple recursive solution


  • 0
    U
    
        int deep = 0;
        int res = 0;
        public int findBottomLeftValue(TreeNode root) {
            travel(root, 1);
            return res;
        }
        
        void travel(TreeNode root, int d) {
            if (root != null) {
                if (d > deep) {
                    deep = d;
                    res = root.val;
                }
                travel(root.left, d+1);
                travel(root.right, d+1);
            }
        }
    

Log in to reply
 

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