海南网站建设推广公司,做网站什么主题好做,51做网站,网站程序代码优化题目#xff1a; 代码(首刷自解 2024年2月18日#xff09;#xff1a; 这题与气球扎针#xff0c;删除重复的大体逻辑相似。需要额外定义些变量来存储头尾
class Solution {
private:const static bool cmp(vectorint a, vectorint b) {return …题目 代码(首刷自解 2024年2月18日 这题与气球扎针删除重复的大体逻辑相似。需要额外定义些变量来存储头尾
class Solution {
private:const static bool cmp(vectorint a, vectorint b) {return a[0] b[0];}
public:vectorvectorint merge(vectorvectorint intervals) {if (intervals.size() 2) return intervals;sort(intervals.begin(), intervals.end(), cmp);vectorvectorint res;int head intervals[0][0];int end intervals[0][1];for (int i 1; i intervals.size(); i) {if (intervals[i][0] end) {end max(intervals[i][1],end);} else {res.push_back(vectorint{head,end});head intervals[i][0];end intervals[i][1];}}res.push_back(vectorint{head,end});return res;}
};