Skip to content

Commit f19ddb7

Browse files
committed
Add solution #111
1 parent c1765c7 commit f19ddb7

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
88|[Merge Sorted Array](./0088-merge-sorted-array.js)|Easy|
4343
94|[Binary Tree Inorder Traversal](./0094-binary-tree-inorder-traversal.js)|Easy|
4444
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|
4546
118|[Pascal's Triangle](./0118-pascals-triangle.js)|Easy|
4647
119|[Pascal's Triangle II](./0119-pascals-triangle-ii.js)|Easy|
4748
121|[Best Time to Buy and Sell Stock](./0121-best-time-to-buy-and-sell-stock.js)|Easy|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
};

0 commit comments

Comments
 (0)