class Solution {
public:
vector<Interval> insert(vector<Interval>& intervals, Interval newInterval) {
vector<Interval> res;
int n = intervals.size(), cur = 0;
while (cur < n && intervals[cur].end < newInterval.start) {
res.push_back(intervals[cur++]);
}
while (cur < n && intervals[cur].start <= newInterval.end) {
newInterval.start = min(newInterval.start, intervals[cur].start);
newInterval.end = max(newInterval.end, intervals[cur].end);
++cur;
}
res.push_back(newInterval);
while (cur < n) {
res.push_back(intervals[cur++]);
}
return res;
}
};
相关文章
- 11-25confidence interval
- 11-25如何在lmfit最小二乘最小化中包含我的数据错误,以及lmfit中conf_interval2d函数的这个错误是什么?
- 11-25was cached in the local repository, resolution will not be reattempted until the update interval of fintech has elapsed or updates are forced
- 11-25was cached in the local repository, resolution will not be reattempted until the update interval of localhost-repository has elapsed or updates are forced
- 11-25转载:最大子段和问题(Maximum Interval Sum)
- 11-25[LeetCode]436 Find Right Interval
- 11-25连接的初步建立和Page Scan interval、Page Scan window、Page Scan Type的选择(为什么有的设备跟手机配对100次失败0-1次,有的确失败3-5次)
- 11-25confidence intervals and precision|The One-Mean z-Interval Procedure|When to Use the One-Mean z-Int
- 11-25INTERVAL
- 11-25LintCode 156: Merge Interval