2024每日刷题(126)
Leetcode—163. 缺失的区间
实现代码
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;}
};
运行结果
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!