代码拉取完成,页面将自动刷新
// Time: O(m + n)
// Space: O(1)
/**
* Definition for an interval.
* struct Interval {
* int start;
* int end;
* Interval() : start(0), end(0) {}
* Interval(int s, int e) : start(s), end(e) {}
* };
*/
class Solution {
public:
vector<Interval> intervalIntersection(vector<Interval>& A, vector<Interval>& B) {
vector<Interval> result;
int i = 0, j = 0;
while (i < A.size() && j < B.size()) {
int left = max(A[i].start, B[j].start);
int right = min(A[i].end, B[j].end);
if (left <= right) {
result.emplace_back(left, right);
}
if (A[i].end < B[j].end) {
++i;
} else {
++j;
}
}
return result;
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。