其他分享
首页 > 其他分享> > 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

标签:乘积,nums,int,713,self,sums,start,数组,List
来源: https://blog.csdn.net/FeNGQiHuALOVE/article/details/115282711