美文网首页
713. Subarray Product Less Than

713. Subarray Product Less Than

作者: xiaoyaook | 来源:发表于2017-11-05 20:02 被阅读0次

    双指针,滑动窗口
    数组长度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

    相关文章

      网友评论

          本文标题:713. Subarray Product Less Than

          本文链接:https://www.haomeiwen.com/subject/ufuhmxtx.html