文章目录
-
- 原题题目
- 代码实现(首刷自解)
原题题目
代码实现(首刷自解)
class Solution {
public:int numOfSubarrays(vector<int>& arr, int k, int threshold) {
int sum = 0,ret = 0,pow_threshold = threshold * k;for(int i = 0;i < k;++i)sum += arr[i];ret += (sum >= pow_threshold);int pos = k,size = arr.size();while(pos < size){
sum += arr[pos];sum -= arr[pos - k];++pos;ret += (sum >= pow_threshold);}return ret;}
};