Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<vector<int>> intervalIntersection(vector<vector<int>>& A, vector<vector<int>>& B) {
- int a, b, a_start, a_end, b_start, b_end;
- a = b = 0;
- vector< vector<int> > res;
- while(a < A.size() && b < B.size()){
- a_start = A[a][0], a_end = A[a][1];
- b_start = B[b][0], b_end = B[b][1];
- if(a_start <= b_end && b_start <= a_end){
- int left = max(a_start, b_start);
- int right = min(a_end, b_end);
- res.push_back(vector<int> {left, right});
- }
- if(a_end <= b_end)
- a++;
- else
- b++;
- }
- return res;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment