Skip to content

Commit

Permalink
Time: 4 ms (77.33%) | Memory: 63.3 MB (39.21%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhieu-it committed Feb 23, 2024
1 parent f8896a9 commit be57404
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 111-minimum-depth-of-binary-tree/minimum-depth-of-binary-tree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
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 minDepth(root.left) + 1;
}
return Math.min(minDepth(root.left), minDepth(root.right)) + 1;
}
}

0 comments on commit be57404

Please sign in to comment.