檢查是否區域內所整數都被覆蓋

BiankaShenhen發表於2024-11-18

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;
}

};

相關文章