986. Interval List Intersections
https://leetcode-cn.com/problems/interval-list-intersections/
class Solution {
public:
vector<vector<int>> intervalIntersection(vector<vector<int>>& A, vector<vector<int>>& B) {
int i = 0, j = 0;
vector<vector<int>> ans;
while (i<A.size()&&j<B.size()){
int left = max(A[i][0], B[j][0]);
int right = min(A[i][1], B[j][1]);
if (right >= left) {
ans.push_back({ left,right });
}
if (A[i][1] < B[j][1]) {
++i;
}
else ++j;
}
return ans;
}
};