class Solution {
public:
vector<Interval> insert(vector<Interval> &intervals, Interval newInterval) {
vector<Interval>res;
for(int i=0;i<intervals.size();i++)
{
if(intervals[i].end<newInterval.start)
res.push_back(intervals[i]);
else
if(newInterval.end<intervals[i].start)
{
res.push_back(newInterval);
res.insert(res.end(),intervals.begin()+i,intervals.end());
return res;
}
else
{
newInterval.start=min(newInterval.start,intervals[i].start);
newInterval.end=max(newInterval.end,intervals[i].end);
}
}
res.push_back(newInterval);
return res;
}
};
笨死了,我的方法要用无数个if else
Insert Interval
最新推荐文章于 2020-11-04 20:53:35 发布