Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int numSubarrayProductLessThanK(vector<int>& nums, int k) {
- if(!k) return 0;
- int product, ans, left, right;
- product = 1;
- ans = 0;
- for(left=0, right=0; right<nums.size(); right++){
- product *= nums[right];
- while(left <= right && product >= k){
- product /= nums[left++];
- }
- ans += (right-left+1);
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement