leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0713.cpp (428B)


      1 class Solution {
      2   public:
      3     int numSubarrayProductLessThanK(vector<int> &nums, int k) {
      4         int res = 0, count = 0, prod = 1, start = 0;
      5         ;
      6         for (int i = 0; i < nums.size(); i++) {
      7             prod *= nums[i];
      8             while (prod >= k && start <= i) {
      9                 prod /= nums[start++];
     10                 count--;
     11             }
     12             res += i - start + 1;
     13         }
     14         return res;
     15     }
     16 };