leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 36a8c18aae0bbe94a596dff3d8d42eb0c31d8cb8 |
parent | a2e4ad2e487451ad788aff860d7764833c6e9a19 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Mon, 6 Feb 2023 14:40:29 +0100 |
Algorithm II: Day 4
Diffstat:A | Problems/0986.cpp | | | +++++++++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/Problems/0986.cpp b/Problems/0986.cpp
@@ -0,0 +1,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;
}
};
diff --git a/README.md b/README.md
@@ -288,6 +288,7 @@ for solving problems.
| 0974 | Medium | [Subarray Sums Divisible by K](Problems/0974.cpp) |
| 0977 | Easy | [Squares of a Sorted Array](Problems/0977.cpp) |
| 0980 | Hard | [Unique Paths III](Problems/0980.cpp) |
| 0986 | Medium | [Interval List Intersections](Problems/0986.cpp) |
| 0989 | Easy | [Add to Array-Form of Integer](Problems/0989.cpp) |
| 0990 | Medium | [Satisfiability of Equality Equations](Problems/0990.cpp) |
| 0993 | Easy | [Cousins in Binary Tree](Problems/0993.cpp) |