Skip to content

Commit 89b4732

Browse files
committed
Create 1288. 删除被覆盖区间.js
1 parent 87e4857 commit 89b4732

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

1288. 删除被覆盖区间.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {number[][]} intervals
3+
* @return {number}
4+
*/
5+
var removeCoveredIntervals = function (intervals) {
6+
intervals.sort((a, b) => {
7+
if (a[0] != b[0]) {
8+
return a[0] - b[0];
9+
} else {
10+
return b[1] - a[1];
11+
}
12+
});
13+
14+
const result = [];
15+
for (const current of intervals) {
16+
if (result.length === 0) {
17+
result.push(current);
18+
} else {
19+
const last = result[result.length - 1];
20+
if (!(current[0] >= last[0] && current[1] <= last[1])) {
21+
result.push(current);
22+
}
23+
}
24+
}
25+
26+
return result.length;
27+
};

0 commit comments

Comments
 (0)