-_-
子数组,没好好看题目,我以为k
个数。。。难怪感觉写的没问题,但是答案确不对。
class Solution {public:int numOfSubarrays(vector<int>& arr, int k, int threshold) {int n = arr.size();vector<int>sum(n + 1,0);sum[0] = arr[0] - threshold;for(int i = 0; i < n; i++){arr[i] -= threshold;sum[i+1] += sum[i] + arr[i]; // sum[0] = 0,sum[i]表示前i个之和}int res = 0;for(int i = k; i <= n; i++){if(sum[i] - sum[i - k] >= 0){res++;}}return res;}};