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 99292bc

Browse files
update: 116
1 parent b133444 commit 99292bc

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
6767
| 108 | [Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/) | [JavaScript](./src/convert-sorted-array-to-binary-search-tree/res.js) | Easy |
6868
| 110 | [balanced-binary-tree](https://leetcode.com/problems/balanced-binary-tree/) | [TypeScript](./src/balanced-binary-tree/res.ts) | Easy |
6969
| 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 |
70-
| 114 | [flatten-binary-tree-to-linked-list](https://leetcode.com/problems/flatten-binary-tree-to-linked-list/) | [JavaScript](./src/flatten-binary-tree-to-linked-list/res.ts) | Medium |
70+
| 114 | [flatten-binary-tree-to-linked-list](https://leetcode.com/problems/flatten-binary-tree-to-linked-list/) | [TypeScript](./src/flatten-binary-tree-to-linked-list/res.ts) | Medium |
71+
| 116 | [populating-next-right-pointers-in-each-node](https://leetcode.com/problems/populating-next-right-pointers-in-each-node/) | [TypeScript](./src/populating-next-right-pointers-in-each-node/res.ts) | Medium |
7172
| 120 | [Triangle](https://leetcode.com/problems/triangle/) | [JavaScript](./src/triangle/res.js) | Medium |
7273
| 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 |
7374
| 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 |
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// @ts-nocheck
2+
3+
/**
4+
* Definition for Node.
5+
*/
6+
class Node {
7+
val: number
8+
left: Node | null
9+
right: Node | null
10+
next: Node | null
11+
constructor(val?: number, left?: Node, right?: Node, next?: Node) {
12+
this.val = (val===undefined ? 0 : val)
13+
this.left = (left===undefined ? null : left)
14+
this.right = (right===undefined ? null : right)
15+
this.next = (next===undefined ? null : next)
16+
}
17+
}
18+
19+
function connect(root: Node | null): Node | null {
20+
if (!root) {
21+
return root;
22+
}
23+
24+
if (!root.left && !root.right) {
25+
root.next = null;
26+
return root;
27+
}
28+
29+
let queues = [root];
30+
while (queues.length) {
31+
const currentLevel = queues.slice();
32+
queues = [];
33+
34+
for (let i=0; i<currentLevel.length; i++) {
35+
if (currentLevel[i].left) {
36+
queues.push(currentLevel[i].left);
37+
}
38+
if (currentLevel[i].right) {
39+
queues.push(currentLevel[i].right);
40+
}
41+
42+
currentLevel[i].next = currentLevel[i+1] ?? null;
43+
}
44+
}
45+
46+
return root;
47+
};

0 commit comments

Comments
(0)

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