C# - recursion 4 lines


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

Log in to reply
 

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