leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1343.cpp (451B)
0 class Solution {
1 public:
2 int numOfSubarrays(const vector<int> &arr, int k, int threshold) {
3 int total = 0, res = 0;
4 for (int i = 0; i < k; i++)
5 total += arr[i];
7 threshold *= k;
8 for (int i = k; i < arr.size(); i++) {
9 if (total >= threshold) res++;
10 total += arr[i];
11 total -= arr[i - k];
12 }
13 if (total >= threshold) res++;
15 return res;
16 }
17 };