Leetcode—56.合并区间【中等】

2023每日刷题(五十七)

Leetcode---56.合并区间

算法思想

实现代码

cpp 复制代码
class Solution {
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        sort(intervals.begin(), intervals.end());
        vector<vector<int>> ans;
        ans.push_back(intervals[0]);
        for(int i = 1; i < intervals.size(); i++) {
            if(ans.back()[1] < intervals[i][0]) {
                ans.push_back(intervals[i]);
            } else {
                ans.back()[1] = max(intervals[i][1], ans.back()[1]);
            }
        }
        return ans;
    }
};

运行结果


之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!

相关推荐
小白菜又菜1 天前
Leetcode 3432. Count Partitions with Even Sum Difference
算法·leetcode
wuhen_n1 天前
LeetCode -- 15. 三数之和(中等)
前端·javascript·算法·leetcode
sin_hielo1 天前
leetcode 2483
数据结构·算法·leetcode
无奈笑天下1 天前
【麒麟镜像vmtools异常排查指导书】
linux·运维·经验分享·云计算·kylin
大数据追光猿1 天前
【大数据Doris】生产环境,Doris主键模型全表7000万数据更新写入为什么那么慢?
大数据·经验分享·笔记·性能优化·doris
Xの哲學1 天前
Linux多级时间轮:高精度定时器的艺术与科学
linux·服务器·网络·算法·边缘计算
大头流矢1 天前
归并排序与计数排序详解
数据结构·算法·排序算法
阿闽ooo1 天前
外观模式:从家庭电源控制看“简化接口“的设计智慧
c++·设计模式·外观模式
油泼辣子多加1 天前
【信创】算法开发适配
人工智能·深度学习·算法·机器学习
不会学习?1 天前
markdown笔记分享
经验分享·笔记