Subarray Product Less Than K

2019-05-25 22:49:53 浏览数 (1)

1. Description

2. Solution

代码语言:javascript复制
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;
    }
};

0 人点赞