Leetcode—163. 缺失的区间【简单】Plus

2024每日刷题(126)

Leetcode---163. 缺失的区间

实现代码

cpp 复制代码
class Solution {
public:
    vector<vector<int>> findMissingRanges(vector<int>& nums, int lower, int upper) {
        int n = nums.size();
        vector<vector<int>> ans;
        if(n == 0) {
            ans.push_back({lower, upper});
            return ans;
        }
        int left = lower, right = upper;
        for(int i = 0; i < n; i++) {
            if(nums[i] == left) {
                left++;
                continue;
            } else {
                ans.push_back({left, nums[i] - 1});
                left = nums[i] + 1;
            }
        }
        if(left <= upper) {
            ans.push_back({left, upper});
        }
        return ans;
    }
};

运行结果

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

相关推荐
划破黑暗的第一缕曙光1 天前
[C++]:1.C++基础
c++·c++基础
TracyCoder1231 天前
LeetCode Hot100(28/100)——104. 二叉树的最大深度
算法·leetcode
执着2591 天前
力扣hot100 - 101、对称二叉树
数据结构·算法·leetcode
努力学算法的蒟蒻1 天前
day77(2.5)——leetcode面试经典150
面试·职场和发展
多恩Stone1 天前
【3D-AICG 系列-1】Trellis v1 和 Trellis v2 的区别和改进
人工智能·pytorch·python·算法·3d·aigc
三月微暖寻春笋1 天前
【和春笋一起学C++】(五十九)派生类和基类之间的关系
c++·基类·派生类·关系
mit6.8241 天前
模运算|z函数 字符串匹配
算法
LaughingZhu1 天前
Product Hunt 每日热榜 | 2026-02-05
大数据·数据库·人工智能·经验分享·搜索引擎·产品运营
阿豪只会阿巴1 天前
【吃饭香系列】二周目|代码随想录算法训练营第七天|454.四数相加II |383. 赎金信 |15. 三数之和 |18. 四数之和
算法
小O的算法实验室1 天前
2025年COR SCI2区,考虑风场影响的无人机搜救覆盖路径规划精确界算法,深度解析+性能实测
算法·无人机·论文复现·智能算法·智能算法改进