leetcode 每日一题 713. 乘积小于 K 的子数组
leetcode 每日一题 713. 乘积小于 K 的子数组
瞎写,自己都不知道写的什么,缺了条件就补条件
class Solution {
public int numSubarrayProductLessThanK(int[] nums, int k) {
int end = 0;
int sum = 1;
int result = 0;
for (int i = 0; i < nums.length; i++) {
if(nums[i] >= k){
end = i+1;
sum = 1;
continue;
}
for (int j = end; j < nums.length; j++) {
if (sum * nums[j] < k) {
sum *= nums[j];
end++;
} else {
break;
}
}
if(end > i){
sum /= nums[i];
result += end - i;
}
if(end == i && i != 0){
result++;
}
if(end < i){
end = i+1;
}
}
return result;
}
}


浙公网安备 33010602011771号