力扣第1248题 统计「优美子数组」

Posted woodjay

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了力扣第1248题 统计「优美子数组」相关的知识,希望对你有一定的参考价值。

力扣第1248题 统计「优美子数组」

技术图片

技术图片

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;
    }
};

以上是关于力扣第1248题 统计「优美子数组」的主要内容,如果未能解决你的问题,请参考以下文章