-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path0986.cpp
More file actions
25 lines (23 loc) · 739 Bytes
/
Copy path0986.cpp
File metadata and controls
25 lines (23 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Solution {
public:
vector<vector<int>> intervalIntersection(vector<vector<int>> &firstList,
vector<vector<int>> &secondList) {
vector<vector<int>> res;
int n = firstList.size(), m = secondList.size(), i = 0, j = 0;
while (i < n && j < m) {
const vector<int> &a = firstList[i], b = secondList[j];
if (a[1] < b[0])
i++;
else if (a[0] > b[1])
j++;
else {
res.push_back({max(a[0], b[0]), min(a[1], b[1])});
if (a[1] < b[1])
i++;
else
j++;
}
}
return res;
}
};