完蛋,简单题都不会写了 不过基本也不找工作了 哎
参考:https://leetcode-cn.com/problems/check-if-all-the-integers-in-a-range-are-covered/solution/yi-ti-san-jie-bao-li-you-hua-chai-fen-by-w7xv/
题目
https://leetcode-cn.com/problems/check-if-all-the-integers-in-a-range-are-covered/
代码
class Solution {
public boolean isCovered(int[][] ranges, int left, int right) {
int m=ranges.length;
if(m==0) return false;
int n=ranges[0].length;
int[] diff=new int[52];
for(int i=0;i<m;i++){
diff[ranges[i][0]]++;
diff[ranges[i][1]+1]--;
}
int cur=0;
for(int i=0;i<diff.length;i++){
cur+=diff[i];
if(left<=i&&i<=right){
if(cur<=0){
return false;
}
}
}
return true;
}
}
|