Skip to content

Commit

Permalink
Create minimum-depth-of-binary-tree.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhieu-it authored May 2, 2024
1 parent 8b05ce9 commit 22a1494
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions 111-minimum-depth-of-binary-tree/minimum-depth-of-binary-tree.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Solution {
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 Math.Min(MinDepth(root.left), MinDepth(root.right)) + 1;
}
}

0 comments on commit 22a1494

Please sign in to comment.