LeetCode 1229. Meeting Scheduler
作者:
Leo_88
,
2024-03-16 10:21:43
,
所有人可见
,
阅读 12
扫描线
代码
class Solution {
public:
vector<int> minAvailableDuration(vector<vector<int>>& slots1, vector<vector<int>>& slots2, int duration) {
sort(slots1.begin(), slots1.end());
sort(slots2.begin(), slots2.end());
int i = 0, j = 0;
while (i < slots1.size() && j < slots2.size()) {
int commonStart = max(slots1[i][0], slots2[j][0]);
int commonEnd = min(slots1[i][1], slots2[j][1]);
if (commonEnd - commonStart >= duration) {
return {commonStart, commonStart + duration};
} else if (slots1[i][1] < slots2[j][1]) i++;
else j++;
}
return {};
}
};