双指针,滑动窗口
数组长度n
n = len(nums)
p记录乘积
p = 1
i为begin,窗口左端. j为end,窗口右端
i = 0 j = 0
total记录符合条件subarray个数
total = 0
while j < n:
p *= nums[j]
while i <= j and p >= k:
p /= nums[i]
i += 1
total += j - i + 1
j += 1
尽量扩展窗口
最后返回total
return total
网友评论