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