We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a99e1a0 commit 2255e02Copy full SHA for 2255e02
README.md
@@ -37,6 +37,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
37
|49|[Group Anagrams](https://leetcode.com/problems/anagrams/) | [JavaScript](./src/anagrams/res.js)|Medium|
38
|54|[Spiral Matrix](https://leetcode.com/problems/spiral-matrix/) | [JavaScript](./src/spiral-matrix/res.js)|Medium|
39
|55|[Jump Game](https://leetcode.com/problems/jump-game/) <sup>*</sup> | [JavaScript](./src/jump-game/res.js)|Medium|
40
+|56|[Merge Intervals](https://leetcode.com/problems/merge-intervals/) | [JavaScript](./src/merge-intervals/res.js)|Medium|
41
|57|[Insert Interval](https://leetcode.com/problems/insert-interval/) | [JavaScript](./src/insert-interval/res.js)|Hard|
42
|66|[Plus One](https://leetcode.com/problems/plus-one/) | [JavaScript](./src/plus-one/res.js)|Easy|
43
|69|[Sqrt(x)](https://leetcode.com/problems/sqrtx/) | [JavaScript](./src/sqrtx/res.js)|Easy|
src/merge-intervals/res.js
@@ -0,0 +1,23 @@
1
+/**
2
+ * @param {number[][]} intervals
3
+ * @return {number[][]}
4
+ */
5
+var merge = function(intervals) {
6
+ intervals.sort((a, b) => a[0]-b[0]);
7
+ const len = intervals.length;
8
+
9
+ res = [];
10
+ i = 0;
11
+ while (i < len) {
12
+ let [left, right] = intervals[i];
13
+ while (i < len-1 && intervals[i+1][0] <= right) {
14
+ i += 1;
15
+ right = Math.max(intervals[i][1], right);
16
+ }
17
+ res.push([left, right]);
18
19
20
21
+ return res;
22
23
+};
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments