```
bool IntervalCompare(Interval a, Interval b)
{
return a.start < b.start;
}
class Solution {
public:
vector<Interval> merge(vector<Interval>& intervals) {
vector<Interval> result;
if(intervals.size() == 0) return result;
sort(intervals.begin(), intervals.end(), IntervalCompare);
result.push_back(intervals[0]);
for(int i=1; i<intervals.size(); i++)
{
if(intervals[i].start <= result.back().end) result.back().end = max(intervals[i].end, result.back().end);
else result.push_back(intervals[i]);
}
return result;
}
};
```