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 7770096 commit 59c7843Copy full SHA for 59c7843
757-set-intersection-size-at-least-two.js
@@ -0,0 +1,28 @@
1
+/**
2
+ * @param {number[][]} intervals
3
+ * @return {number}
4
+ */
5
+const intersectionSizeTwo = function(intervals) {
6
+ intervals.sort((a, b) => a[1] - b[1]);
7
+
8
+ let n = intervals.length;
9
+ if (n === 0) return 0;
10
11
+ let count = 2;
12
+ let last = intervals[0][1];
13
+ let sec_last = intervals[0][1] - 1;
14
15
+ for (let i = 1; i < n; i++) {
16
+ if (intervals[i][0] <= sec_last) continue;
17
+ else if (intervals[i][0] <= last) {
18
+ sec_last = last;
19
+ last = intervals[i][1];
20
+ count++;
21
+ } else {
22
23
+ sec_last = intervals[i][1] - 1;
24
+ count += 2;
25
+ }
26
27
+ return count;
28
+};
0 commit comments