文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
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
- https://leetcode.com/problems/subarray-product-less-than-k/description/