Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 37173fd

Browse files
update: 107
1 parent ca696fa commit 37173fd

File tree

3 files changed

+55
-17
lines changed

3 files changed

+55
-17
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
5555
|101|[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/) | [JavaScript](./src/symmetric-tree/res.js)|Easy|
5656
|102|[Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/) | [JavaScript](./src/binary-tree-level-order-traversal/res.js)|Medium|
5757
|107|[Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii/) | [JavaScript](./src/binary-tree-level-order-traversal-ii/res.js)|Easy|
58+
|111|[Minimum Depth of Binary Tree](https://leetcode.com/problems/minimum-depth-of-binary-tree/) | [JavaScript](./src/minimum-depth-of-binary-tree/res.js)|Easy|
5859
|120|[Triangle](https://leetcode.com/problems/triangle/) | [JavaScript](./src/triangle/res.js)|Medium|
5960
|121|[Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) | [JavaScript](./src/best-time-to-buy-and-sell-stock/res.js)|Easy|
6061
|122|[Best Time to Buy and Sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/) | [JavaScript](./src/best-time-to-buy-and-sell-stock-ii/res.js)|Easy|

‎src/binary-tree-level-order-traversal-ii/res.js‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@
77
*/
88
/**
99
* @param {TreeNode} root
10-
* @return {number}
10+
* @return {number[][]}
1111
*/
12-
var minDepth = function(root) {
13-
if (!root) return 0;
12+
var levelOrderBottom = function(root) {
13+
if (!root) return [];
1414

15-
let queue = [root];
16-
let res = 1;
17-
18-
while(queue.length) {
15+
const getDepthNodes = (queue) => {
1916
const tempQ = [];
20-
let isNull = false;
21-
17+
const tempR = [];
2218
queue.map(e => {
23-
if (!e.left&&!e.right)isNull=true;
19+
if (e.val!==undefined)tempR.push(e.val);
2420

25-
e.left && tempQ.push(e.left);
26-
e.right && tempQ.push(e.right);
21+
if (e.left) {
22+
tempQ.push(e.left);
23+
}
24+
if (e.right) {
25+
tempQ.push(e.right);
26+
}
2727
});
28-
queue=tempQ;
29-
if (isNull) {
30-
break;
28+
29+
if (tempQ.length) {
30+
returngetDepthNodes(tempQ).concat([tempR]);
3131
} else {
32-
res+=1;
32+
return[tempR];
3333
}
3434
}
3535

36-
return res;
36+
return getDepthNodes([root]);
3737
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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) return 0;
14+
15+
let queue = [root];
16+
let res = 1;
17+
18+
while(queue.length) {
19+
const tempQ = [];
20+
let isNull = false;
21+
22+
queue.map(e => {
23+
if (!e.left && !e.right) isNull = true;
24+
25+
e.left && tempQ.push(e.left);
26+
e.right && tempQ.push(e.right);
27+
});
28+
queue = tempQ;
29+
if (isNull) {
30+
break;
31+
} else {
32+
res += 1;
33+
}
34+
}
35+
36+
return res;
37+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /