Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool mySort(vector<int> A,vector<int> B){
- return A[0]<B[0] || (A[0]==B[0] && A[1]<B[1]);
- }
- vector<vector<int> > mergeIntervals(vector<vector<int> > &intervals) {
- sort(intervals.begin(),intervals.end(),mySort);
- vector<vector<int> > res;
- vector<int> A,B;
- A=intervals[0];
- bool flag=false;
- for(int i=0;i<intervals.size();i++){
- B=intervals[i];
- if(B[0]<=A[1]){
- A[1]=max(A[1],B[1]);
- }else{
- res.push_back(A);
- A=B;
- }
- }
- res.push_back(A);
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement