检查是否区域内所整数都被覆盖

https://leetcode.cn/problems/check-if-all-the-integers-in-a-range-are-covered/description/

class Solution {
public:
bool isCovered(vector<vector>& ranges, int left, int right) {
vector diff(52,0);
for(auto a:ranges){
++diff[a[0]];
--diff[a[1]+1];
}
int count=0;
for(int i=0;i<=50;i++){
count+=diff[i];
if(i>=left&&i<=right&&count<=0)
return false;
}

return true;
}

};

posted @ 2024-11-18 00:14  BiankaShenhen  阅读(1)  评论(0编辑  收藏  举报