We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 99f8eb4 commit 01c2136Copy full SHA for 01c2136
1 file changed
LeetCode/Easy/0111-minimum-depth-of-binary-tree/0111-minimum-depth-of-binary-tree.java
@@ -20,17 +20,13 @@ class Solution {
20
int minDepth=0;
21
22
public int minDepth(TreeNode root) {
23
- if(root == null) return minDepth;
+ if(root == null) return 0;
24
//dfs
25
- // if(root.left==null&&root.right==null) return minDepth;
26
- if(root.left==null && root.right==null) return 1+minDepth;
+ if(root.left==null && root.right==null) return 1;
27
else if(root.left==null) return 1+minDepth(root.right);
28
else if(root.right==null) return 1+minDepth(root.left);
29
else return 1+Math.min(minDepth(root.left), minDepth(root.right));
30
31
- // minDepth = 1+Math.min(minDepth(root.left), minDepth(root.right));
32
-
33
- // return minDepth;
34
// //bfs
35
// if(root == null) return 0;
36
0 commit comments