力扣56.合并区间
-
按左端点排序
- 判断左端点是否小于等于当前右端点**(可以合并)**
-
class Solution { public: vector<vector<int>> merge(vector<vector<int>>& intervals) { ranges::sort(intervals); vector<vector<int>> res; for(auto &t:intervals) { if(!res.empty() && t[0] <= res.back()[1]) res.back()[1] = max(res.back()[1],t[1]); else res.emplace_back(t); } return res; } };