class Solution {
public int numberOfArrays(int[] differences, int lower, int upper) {
int number = 0;
int min = differences[0];
int max = differences[0];
int sum = 0;
for(int i = 0;i<differences.length;i++){
sum += differences[i];
min = Math.min(min,sum);
max = Math.max(max,sum);
}
for(int j = 0; j < upper - lower + 1; j++){
if(lower + j + min >= lower &&
lower + j + max <= upper){
number++;
}
}
return number;
}
}
统计隐藏数目数组
最新推荐文章于 2024-10-30 22:30:35 发布