Simple Java Recursion Solution


  • 0
    S
    public int minDepth(TreeNode root){
        if(root==null) return 0;
        return helper(root,1);
    }
    
    public int helper(TreeNode root,int depth){
        if(root==null) return Integer.MAX_VALUE;
        if(root.left==null && root.right==null) return depth;
        return Math.min(helper(root.left,depth+1),helper(root.right,depth+1));
    }

Log in to reply
 

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