My 75ms C# solution


  • 0
    S
    public int MinDepth(TreeNode root) {
        if(root == null){
            return 0;
        }
        if(root.left == null && root.right == null){
            return 1;
        }
        if(root.left == null){
            return MinDepth(root.right) + 1;
        }
        if(root.right == null){
            return MinDepth(root.left) + 1;
        }
        return Math.Min(MinDepth(root.left), MinDepth(root.right)) + 1;
    }

Log in to reply
 

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