当前位置: 代码迷 >> 综合 >> Leetcode 713. Subarray Product Less Than K
  详细解决方案

Leetcode 713. Subarray Product Less Than K

热度:11   发布时间:2023-12-12 21:21:30.0

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Subarray Product Less Than K

2. Solution

class Solution {
public:int numSubarrayProductLessThanK(vector<int>& nums, int k) {if(k <= 1) {return 0;} int i = 0;int j = 0;int count = 0;int product = 1;while(j < nums.size()) {product *= nums[j];while(product >= k) {product /= nums[i];i++;}count += j - i + 1;j++;}return count;}
};

Reference

  1. https://leetcode.com/problems/subarray-product-less-than-k/description/
  相关解决方案