class Solution {
public:
static bool IntervalCompare(Interval &a, Interval &b){
return (a.start<b.start);
}
vector<Interval> merge(vector<Interval>& intervals) {
int k=intervals.size();
if (k<=1) return intervals;
sort(intervals.begin(),intervals.end(),IntervalCompare);
vector<Interval> res;
for (int i=0;i<k1;i++){
if (intervals[i].end>=intervals[i+1].end) {
intervals[i+1].end = intervals[i].end;
intervals[i+1].start = intervals[i].start;
}
else if (intervals[i].end>=intervals[i+1].start){
intervals[i+1].start = intervals[i].start;
}
else res.push_back(intervals[i]);
}
res.push_back(intervals[k1]);
return res;
}
};
C++ 580ms solution sort first O(nlogn), then O(n) time, O(1) space


@rmn The title accurately describes the time complexity of each major part of the codes. That is it.