标签:public png ++ vector turn c++ subarray 统计 array
class Solution {
public:
int numberOfSubarrays(vector<int>& nums, int k)
{
int len = nums.size();
vector<int> cnt(len + 1, 0);
int res = 0, odd = 0;
cnt[0] = 1;
for (int i = 0; i < len; i++)
{
odd += nums[i] & 1;
res += odd >= k ? cnt[odd - k] : 0;
cnt[odd] += 1;
}
return res;
}
};
标签:public png ++ vector turn c++ subarray 统计 array
原文地址:https://www.cnblogs.com/woodjay/p/12764702.html