Untitled
unknown
plain_text
a year ago
853 B
11
Indexable
Never
class cmp{ public: bool operator()(vector<int> a,vector<int> b){ if(a[0]==b[0]) return a[1]<b[1]; return a[0]<b[0]; } }; class Solution { public: vector<vector<int>> merge(vector<vector<int>>& intervals) { vector<vector<int>> res; sort(intervals.begin(),intervals.end(),cmp()); int n=intervals.size(); int r=1,l=0; while(r<n){ if(intervals[r][0] <= intervals[l][1]){ intervals[l][1]=max(intervals[r][1],intervals[l][1]); intervals.erase(intervals.begin()+r); }else{ // res.push_back(intervals[r]); res.push_back(intervals[l]); l=r; r++; } } res.push_back(intervals[l]); return res; } };