Java solution java


  • 4
    G
    public int minDepth(TreeNode root) {
            if(root==null) 
                return 0;
            int a = minDepth(root.left);
            int b = minDepth(root.right);
            if((a+b)==0)
                return 1;
            if(a*b==0)
                return a+b+1;
            if(a<b)
            {return a+1;}
            else {return b+1;}
        }

  • 0
    Z

    Concise and simple, good example of recursive solution.


Log in to reply
 

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