Skip to content

Commit e9b87b1

Browse files
committed
Runtime: 166 ms (Top 33.07%) | Memory: 48.3 MB (Top 80.35%)
1 parent 913b9b2 commit e9b87b1

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1+
// Runtime: 166 ms (Top 33.07%) | Memory: 48.3 MB (Top 80.35%)
12
var intervalIntersection = function(firstList, secondList) {
23
//if a overlap b - a.start >= b.start && a.start <= b.end
34
//if b overlap a - b.start >= a.start && b.start <= a.end
4-
5+
56
//handle empty edge cases
67
if(firstList.length === 0 || secondList.length === 0){
78
return [];
89
}
9-
10+
1011
let merged = [];
1112
let i =0;
1213
let j = 0;
1314
while(i<firstList.length && j < secondList.length){
1415
let a_overlap_b = firstList[i][0] >= secondList[j][0] && firstList[i][0] <= secondList[j][1];
1516
let b_overlap_a = secondList[j][0] >= firstList[i][0] && secondList[j][0] <= firstList[i][1];
16-
17+
1718
if(a_overlap_b || b_overlap_a){
1819
let start = Math.max(firstList[i][0], secondList[j][0]);
1920
let end = Math.min(firstList[i][1], secondList[j][1]);
2021
merged.push([start, end]);
2122
}
22-
23+
2324
if(firstList[i][1] < secondList[j][1]){
2425
i++;
2526
}else {
2627
j++;
2728
}
2829
}
29-
30+
3031
return merged;
31-
32-
};
32+
33+
};

0 commit comments

Comments
 (0)