713. 乘积小于K的子数组

713. 乘积小于K的子数组

滑动窗口

class Solution:
    def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int:
        
        start = 0
        sums = 1
        ans = 0
        for i in range(len(nums)):
            sums = sums * nums[i]
            while sums >= k and start <= i:
                sums = sums // nums[start]
                start = start + 1
            if sums < k:
                ans = ans + i-start+1
        return ans

上一篇:leetcode40 - Combination Sum II - medium


下一篇:leetcode题解之39. 组合总和