713. Subarray Product Less Than K

Обновлено: 2024-03-31
1 мин
[]

Содержание

LeetCode problem 713

class Solution:
    def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int:
        res, s, j = 0, 1, 0
        for i, v in enumerate(nums):
            s *= v
            while j <= i and s >= k:
                s //= nums[j]
                j += 1
            res += i - j + 1
        return res