class Solution {
public:
vector<string> findMissingRanges(vector<int>& nums, int lower, int upper) {
vector<string> ans;
for(auto num:nums){
if(lower==num){
lower+=1;
continue;
}
else if((num-lower)==1){
ans.push_back(std::to_string(lower));
}
else{
ans.push_back(std::to_string(lower)+"->"+std::to_string(num-1));
}
lower=num+1;
}
if(lower==upper){
ans.push_back(std::to_string(upper));
}
else if(upper>lower){
ans.push_back(std::to_string(lower)+"->"+std::to_string(upper));
}
return ans;
}
};
163. 缺失的区间
最新推荐文章于 2024-08-15 05:02:54 发布