当前位置:网站首页>Leetcode-713 subarray with product less than k

Leetcode-713 subarray with product less than k

2022-06-11 00:03:00 It was the sea

 Insert picture description here

class Solution(object):
    def numSubarrayProductLessThanK(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: int
        """
        if k <= 1: return 0
        left, right, multi, ans = 0, 0, 1, 0

        while right < len(nums):

            multi *= nums[right] #  Take the right element as the pivot

            while multi >= k: #  Find the corresponding pivot The point on the left of the longest window 
                multi //= nums[left]
                left += 1
           

            ans += right - left + 1 #  Statistics to pivot The right side of the array is the child element of 
            right += 1

        return ans

原网站

版权声明
本文为[It was the sea]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020932440968.html