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 c0cf5f9

Browse files
Add solution to 986.
1 parent ce31909 commit c0cf5f9

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {number[][]} firstList
3+
* @param {number[][]} secondList
4+
* @return {number[][]}
5+
*/
6+
var intervalIntersection = function (A, B) {
7+
let i = 0,
8+
j = 0;
9+
const out = [];
10+
11+
while (i < A.length && j < B.length) {
12+
const lo = Math.max(A[i][0], B[j][0]);
13+
const hi = Math.min(A[i][1], B[j][1]);
14+
15+
if (lo <= hi) {
16+
out.push([lo, hi]);
17+
}
18+
19+
if (A[i][1] < B[j][1]) {
20+
i++;
21+
} else {
22+
j++;
23+
}
24+
}
25+
26+
return out;
27+
};

0 commit comments

Comments
(0)

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