```
static bool cmp(const Interval i1, const Interval i2) {
return i1.start <= i2.start;
}
vector<Interval> merge(vector<Interval>& intervals) {
if (intervals.size() <= 1) {
return intervals;
}
sort(intervals.begin(), intervals.end(), cmp);
vector<Interval> res;
res.push_back(intervals[0]);
for (int i = 1; i < intervals.size(); ++i) {
if (intervals[i].start > res.back().end) {
res.push_back(intervals[i]);
continue;
}
res.back().end = max(intervals[i].end, res.back().end);
}
return res;
}
```