leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0986.cpp (739B)


0 class Solution {
1 public:
2 vector<vector<int>> intervalIntersection(vector<vector<int>> &firstList,
3 vector<vector<int>> &secondList) {
4 vector<vector<int>> res;
6 int n = firstList.size(), m = secondList.size(), i = 0, j = 0;
7 while (i < n && j < m) {
8 const vector<int> &a = firstList[i], b = secondList[j];
9 if (a[1] < b[0])
10 i++;
11 else if (a[0] > b[1])
12 j++;
13 else {
14 res.push_back({max(a[0], b[0]), min(a[1], b[1])});
15 if (a[1] < b[1])
16 i++;
17 else
18 j++;
19 }
20 }
22 return res;
23 }
24 };