1 2 3 4 5 6 7 8 9 10 11 12 13
| class Solution { public: int numSubarrayProductLessThanK(vector<int>& nums, int k) { int n = nums.size(), ans = 0; for (int left = 0, right = 0, product = 1; right < n; ++right) { product *= nums[right]; while (left <= right && product >= k) product /= nums[left++]; ans += right - left + 1; } return ans; } };
|