Merge Overlapping Intervals
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
vector<Interval> Solution::merge(vector<Interval> &A) { sort(begin(A), end(A), [](auto a, auto b) { return a.start < b.start; }); vector<Interval> res; for(auto& a : A) { if(res.empty() or res.back().end < a.start) res.push_back(a); else res.back().end = max(res.back().end, a.end); } return res; }
|