class Solution {public: vector insert(vector & intervals, Interval newInterval) { vector 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; }};