Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. class Solution {
  2. public:
  3. int numSubarrayProductLessThanK(vector<int>& nums, int k) {
  4. int counter = 0;
  5. if (k <= 1) return counter;
  6.  
  7. int i1 = 0;
  8. int prod = 1;
  9.  
  10. for (int i2 = 0; i2 < nums.size(); ++i2) {
  11. prod *= nums[i2];
  12.  
  13. while (prod >= k) {
  14. prod /= nums[i1];
  15. ++i1;
  16. }
  17.  
  18. counter += i2 - i1 + 1;
  19. }
  20.  
  21. return counter;
  22. }
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement