区间合并
贪心思想
class Solution {
public:
vector<vector<int>> merge(vector<vector<int>>& intervals)
{
vector<vector<int>> res;
sort(intervals.begin(), intervals.end());
vector<int> sted(2, -1);
for (int i = 0; i < intervals.size(); i++)
if (intervals[i][0] > sted[1])
{
if (sted[0] != -1) res.push_back(sted);
sted[0] = intervals[i][0], sted[1] = intervals[i][1];
}
else sted[1] = max(sted[1], intervals[i][1]);
if (sted[0] != -1) res.push_back(sted);
return res;
}
};