Recursive c# solution


  • 0
    K
    public class Solution {
        public int MinDepth(TreeNode root) {
            
            if (root == null) return 0;
            
            if (root.right == null)
                return MinDepth(root.left)+1;
            else if (root.left == null)
                return MinDepth(root.right)+1;
            else
            {
                int i = MinDepth(root.left);
                int j = MinDepth(root.right);
                return Math.Min(i,j)+1;
            }
        }
    }
    

Log in to reply
 

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