leetcode

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

1343.cpp (451B)


      1 class Solution {
      2   public:
      3     int numOfSubarrays(const vector<int> &arr, int k, int threshold) {
      4         int total = 0, res = 0;
      5         for (int i = 0; i < k; i++)
      6             total += arr[i];
      7 
      8         threshold *= k;
      9         for (int i = k; i < arr.size(); i++) {
     10             if (total >= threshold) res++;
     11             total += arr[i];
     12             total -= arr[i - k];
     13         }
     14         if (total >= threshold) res++;
     15 
     16         return res;
     17     }
     18 };