Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 756ed1a

Browse files
committedApr 8, 2025
Add solution #1288
1 parent c2db5c4 commit 756ed1a

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,210 LeetCode solutions in JavaScript
1+
# 1,211 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -972,6 +972,7 @@
972972
1284|[Minimum Number of Flips to Convert Binary Matrix to Zero Matrix](./solutions/1284-minimum-number-of-flips-to-convert-binary-matrix-to-zero-matrix.js)|Hard|
973973
1286|[Iterator for Combination](./solutions/1286-iterator-for-combination.js)|Medium|
974974
1287|[Element Appearing More Than 25% In Sorted Array](./solutions/1287-element-appearing-more-than-25-in-sorted-array.js)|Easy|
975+
1288|[Remove Covered Intervals](./solutions/1288-remove-covered-intervals.js)|Medium|
975976
1290|[Convert Binary Number in a Linked List to Integer](./solutions/1290-convert-binary-number-in-a-linked-list-to-integer.js)|Easy|
976977
1291|[Sequential Digits](./solutions/1291-sequential-digits.js)|Medium|
977978
1292|[Maximum Side Length of a Square with Sum Less than or Equal to Threshold](./solutions/1292-maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshold.js)|Medium|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* 1288. Remove Covered Intervals
3+
* https://leetcode.com/problems/remove-covered-intervals/
4+
* Difficulty: Medium
5+
*
6+
* Given an array intervals where intervals[i] = [li, ri] represent the interval [li, ri), remove
7+
* all intervals that are covered by another interval in the list.
8+
*
9+
* The interval [a, b) is covered by the interval [c, d) if and only if c <= a and b <= d.
10+
*
11+
* Return the number of remaining intervals.
12+
*/
13+
14+
/**
15+
* @param {number[][]} intervals
16+
* @return {number}
17+
*/
18+
var removeCoveredIntervals = function(intervals) {
19+
intervals.sort((a, b) => a[0] - b[0] || b[1] - a[1]);
20+
21+
let result = 1;
22+
let currentEnd = intervals[0][1];
23+
24+
for (let i = 1; i < intervals.length; i++) {
25+
if (intervals[i][1] > currentEnd) {
26+
result++;
27+
currentEnd = intervals[i][1];
28+
}
29+
}
30+
31+
return result;
32+
};

0 commit comments

Comments
 (0)
Please sign in to comment.