Can someone please tell me where I am wrong


  • 0
    S

    public class Solution {
    public int minDepth(TreeNode root) {
    if(root == null){
    return 0;
    }
    int min =calminDepth(root, 0);
    return min;
    }

    private int calminDepth(TreeNode node, int level){
        if(node == null){
            return level;
        }
        
        int leftlevel = calminDepth(node.left, level+1);
        int rightlevel = calminDepth(node.right, level+1);
        
        if(leftlevel == rightlevel )
            return leftlevel ;
        else
            return leftlevel<rightlevel? leftlevel:rightlevel;
        
    }
    

    }


Log in to reply
 

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