File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 42
42
88|[ Merge Sorted Array] ( ./0088-merge-sorted-array.js ) |Easy|
43
43
94|[ Binary Tree Inorder Traversal] ( ./0094-binary-tree-inorder-traversal.js ) |Easy|
44
44
102|[ Binary Tree Level Order Traversal] ( ./0102-binary-tree-level-order-traversal.js ) |Medium|
45
+ 111|[ Minimum Depth of Binary Tree] ( ./0111-minimum-depth-of-binary-tree.js ) |Easy|
45
46
118|[ Pascal's Triangle] ( ./0118-pascals-triangle.js ) |Easy|
46
47
119|[ Pascal's Triangle II] ( ./0119-pascals-triangle-ii.js ) |Easy|
47
48
121|[ Best Time to Buy and Sell Stock] ( ./0121-best-time-to-buy-and-sell-stock.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 111. Minimum Depth of Binary Tree
3
+ * https://leetcode.com/problems/minimum-depth-of-binary-tree/
4
+ * Difficulty: Easy
5
+ *
6
+ * Given a binary tree, find its minimum depth.
7
+ *
8
+ * The minimum depth is the number of nodes along the shortest path from the
9
+ * root node down to the nearest leaf node.
10
+ *
11
+ * Note: A leaf is a node with no children.
12
+ */
13
+
14
+ /**
15
+ * Definition for a binary tree node.
16
+ * function TreeNode(val, left, right) {
17
+ * this.val = (val===undefined ? 0 : val)
18
+ * this.left = (left===undefined ? null : left)
19
+ * this.right = (right===undefined ? null : right)
20
+ * }
21
+ */
22
+ /**
23
+ * @param {TreeNode } root
24
+ * @return {number }
25
+ */
26
+ var minDepth = function ( root ) {
27
+ if ( ! root ) {
28
+ return 0 ;
29
+ }
30
+ const [ left , right ] = [ root . left , root . right ] . map ( minDepth ) ;
31
+ return 1 + ( Math . min ( left , right ) || Math . max ( left , right ) ) ;
32
+ } ;
You can’t perform that action at this time.
0 commit comments