Skip to content

Commit 040e17e

Browse files
committed
update: 102
1 parent be6fe18 commit 040e17e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
5353
|91|[Decode Ways](https://leetcode.com/problems/decode-ways/) | [JavaScript](./src/decode-ways/res.js)|Medium|
5454
|93|[Restore IP Addresses](https://leetcode.com/problems/restore-ip-addresses/) | [JavaScript](./src/restore-ip-addresses/res.js)|Medium|
5555
|101|[Symmetric Tree](https://leetcode.com/problems/symmetric-tree/) | [JavaScript](./src/symmetric-tree/res.js)|Easy|
56+
|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|
5657
|120|[Triangle](https://leetcode.com/problems/triangle/) | [JavaScript](./src/triangle/res.js)|Medium|
5758
|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|
5859
|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|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 levelOrder = function(root) {
13+
if (!root) return [];
14+
15+
let queue = [root];
16+
const res = [];
17+
18+
while(queue.length) {
19+
const tempQ = [];
20+
const tempR = [];
21+
queue.map(e => {
22+
if (e.val !== undefined) tempR.push(e.val);
23+
24+
if (e.left) {
25+
tempQ.push(e.left);
26+
}
27+
if (e.right) {
28+
tempQ.push(e.right);
29+
}
30+
});
31+
queue = tempQ;
32+
res.push(tempR);
33+
}
34+
35+
return res;
36+
};

0 commit comments

Comments
 (0)