固定右端点,求左端点的起始位置到右端点的长度,相加
class Solution {
public int numSubarrayProductLessThanK(int[] nums, int k) {
int l = 0, r = 0, res = 0, p = 1;
while (r < nums.length) {
p *= nums[r++];
while (p >= k && l < r){
p /= nums[l++];
}
res += r - l;
}
return res;
}
}