2024年7月13日 星期六

[713] Subarray Product Less Than K

嗯,很好,我發現我還是不會sliding window!(大哭)

int numSubarrayProductLessThanK(int* nums, int numsSize, int k) {
int l=0, r=0;
int ret=0;
long long product=1;
if (k<=1)
return 0;
while (r< numsSize)
{
product *= nums[r++];
while (product>=k)
product /= nums[l++];
ret+= (r-l);
}
return ret;
}

沒有留言:

張貼留言