vector<vector<int>>merge(vector<vector<int>>& intervals){// 排序sort(intervals.begin(), intervals.end());// 合并区间
vector<vector<int>> ret;int left = intervals[0][0], right = intervals[0][1];for(int i =0; i < intervals.size(); i++){int a = intervals[i][0], b = intervals[i][1];if(a <= right)// 有重叠{
right =max(right, b);}else// 无重叠{
ret.push_back({left, right});
left = a;
right = b;}}// 最后一个区间
ret.push_back({left, right});return ret;}
2.无重叠区间
1.题目链接
无重叠区间
2.算法原理详解
解法:排序(左端点) + 贪心
问题转化:移除最少区间 <–> 保留更多区间
优先干掉右端点长的区间 --> 长的区间更后续区间重叠的概率更大
3.代码实现
interaseOverlapIntervals(vector<vector<int>>& intervals){// 排序sort(intervals.begin(), intervals.end());// 移除区间int ret =0;int left = intervals[0][0], right = intervals[0][1];for(int i =1; i < intervals.size(); i++){int a = intervals[i][0], b = intervals[i][1];if(a < right)// 有重叠{
ret++;// DELETE
right =min(right, b);// 贪心, 删除右端点较大的区间}else// 无重叠{
right = b;}}return ret;}
intfindMinArrowShots(vector<vector<int>>& points){// 排序sort(points.begin(), points.end());// 求互相重叠区间的数量int right = points[0][1];int ret =1;for(int i =1; i < points.size(); i++){int a = points[i][0], b = points[i][1];if(a <= right)// 有重叠{
right =min(right, b);}else// 无重叠{
ret++;
right = b;}}return ret;}
目录
连接至HTB服务器并启动靶机
1.What does the acronym CVE stand for?
2.What do the three letters in CIA, referring to the CIA triad in cybersecurity, stand for?
3.What is the version of the service running on port 8080?
4.What version of Jenkins i…