class Solution { public: static bool cmp(vector<int> a,vector<int> b){ return a[0]<b[0]; } vector<vector<int>> merge(vector<vector<int>>& intervals) { vector<vector<int>> res; sort(intervals.begin(),intervals.end(),cmp); for(int i=0;i<intervals.size();i++){ int x=intervals[i][0];int y=intervals[i][1]; while(i+1<intervals.size()&&y>=intervals[i+1][0]){ i++; y=max(intervals[i][1],y); } res.push_back({x,y}); } return res; } };