File tree 3 files changed +29
-1
lines changed
3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 79
79
| [ 107] [ 107-question ] | [ Binary Tree Level Order Traversal II] [ 107-tips ] | [ Easy] [ E ] | [ ✅] [ 107-java ] | [ ✅] [ 107-js ] | [ ✅] [ 107-kotlin ] |
80
80
| [ 108] [ 108-question ] | [ Convert Sorted Array to Binary Search Tree] [ 108-tips ] | [ Easy] [ E ] | [ ✅] [ 108-java ] | [ ✅] [ 108-js ] | [ ✅] [ 108-kotlin ] |
81
81
| [ 110] [ 110-question ] | [ Balanced Binary Tree] [ 110-tips ] | [ Easy] [ E ] | [ ✅] [ 110-java ] | [ ✅] [ 110-js ] | [ ✅] [ 110-kotlin ] |
82
- | [ 111] [ 111-question ] | [ Minimum Depth of Binary Tree] [ 111-tips ] | [ Easy] [ E ] | [ ✅] [ 111-java ] | | [ ✅] [ 111-kotlin ] |
82
+ | [ 111] [ 111-question ] | [ Minimum Depth of Binary Tree] [ 111-tips ] | [ Easy] [ E ] | [ ✅] [ 111-java ] | [ ✅ ] [ 111-js ] | [ ✅] [ 111-kotlin ] |
83
83
| [ 112] [ 112-question ] | [ Path Sum] [ 112-tips ] | [ Easy] [ E ] | [ ✅] [ 112-java ] | | [ ✅] [ 112-kotlin ] |
84
84
| [ 118] [ 118-question ] | [ Pascal's Triangle] [ 118-tips ] | [ Easy] [ E ] | [ ✅] [ 118-java ] | | [ ✅] [ 118-kotlin ] |
85
85
| [ 119] [ 119-question ] | [ Pascal's Triangle II] [ 119-tips ] | [ Easy] [ E ] | [ ✅] [ 119-java ] | | [ ✅] [ 119-kotlin ] |
@@ -459,6 +459,7 @@ commit信息模板: ``feat: add the solution of `Two Sum`(001) with Java``
459
459
[ 107-js ] : ./src/_107/Solution.js
460
460
[ 108-js ] : ./src/_108/Solution.js
461
461
[ 110-js ] : ./src/_110/Solution.js
462
+ [ 111-js ] : ./src/_111/Solution.js
462
463
[ 226-js ] : ./src/_226/Solution.js
463
464
[ 561-js ] : ./src/_561/Solution.js
464
465
[ 643-js ] : ./src/_643/Solution.js
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val) {
4
+ * this.val = val;
5
+ * this.left = this.right = null;
6
+ * }
7
+ */
8
+ /**
9
+ * @param {TreeNode } root
10
+ * @return {number }
11
+ */
12
+ var minDepth = function ( root ) {
13
+ if ( root == null ) return 0
14
+ if ( root . left === null && root . right === null ) { return 1 }
15
+ if ( root . left === null && root . right !== null ) { return 1 + minDepth ( root . right ) }
16
+ if ( root . left !== null && root . right === null ) { return 1 + minDepth ( root . left ) }
17
+ return 1 + Math . min ( minDepth ( root . left ) , minDepth ( root . right ) )
18
+ } ;
Original file line number Diff line number Diff line change @@ -48,6 +48,15 @@ class Solution {
48
48
}
49
49
```
50
50
51
+ ``` JavaScript
52
+ var minDepth = function (root ) {
53
+ if (root == null ) return 0
54
+ if (root .left === null && root .right === null ) {return 1 }
55
+ if (root .left === null && root .right !== null ) {return 1 + minDepth (root .right )}
56
+ if (root .left !== null && root .right === null ) {return 1 + minDepth (root .left )}
57
+ return 1 + Math .min (minDepth (root .left ),minDepth (root .right ))
58
+ };
59
+ ```
51
60
## 思路 1
52
61
53
62
第二种思路就是利用宽搜了,搜索到该层有叶子节点,那就返回该层宽度即可。
You can’t perform that action at this time.
0 commit comments