Simple Java 7ms


  • 0
    V
        int maxDepth = -1, toRet;
        public int findBottomLeftValue(TreeNode root) 
        {
            recMeth(root, 0);
            return toRet;
        }
        void recMeth(TreeNode root, int depth)
        {
            if(root == null)
                return;
            if(root.left == root.right && root.left == null)
            {
                if(maxDepth < depth)
                {
                    maxDepth = depth;
                    toRet = root.val;
                }
                return;
            }
            recMeth(root.left, depth + 1);
            recMeth(root.right, depth + 1);
        }

Log in to reply
 

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