[虚拟机OA]Even Subarray 最多含有K个奇数的子数组

Posted liuliu5151

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[虚拟机OA]Even Subarray 最多含有K个奇数的子数组相关的知识,希望对你有一定的参考价值。

A subarray is a contiguous portion of an array. Given an array of integers, you must determine the number of distinct subarrays that can be formed having at most a given number of odd elements. Two subarrays are distinct if they differ at even one position in their contents.

For example, if numbers = [1, 2, 3, 4] and the maximum number of odd elements allowed, k = 1, the following is a list of the 8 distinct valid subarrays:
[[1], [2], [3], [4], [1,2], [2, 3], [3, 4], [2, 3, 4]]

 

 

Function Description
Complete the function evenSubarray in the editor below. The function must return the number of distinct subarrays that can be formed per the restriction of k.

evenSubarray has the following parameter(s):
numbersThumbers[0],...numbers[n-1]]: an array of integers
k: the maximum number of odd elements that can be in a subarray 

 

题意:

给定数组,返回包含最多K个奇数的subarray的个数

 

思路:

 

代码:

 

以上是关于[虚拟机OA]Even Subarray 最多含有K个奇数的子数组的主要内容,如果未能解决你的问题,请参考以下文章

[虚拟机OA]Team Formation 2 团队构成

[虚拟机OA]Break a Palindrome 破坏回文串

[虚拟机OA]Fun with Anagrams 玩转同构词

[虚拟机OA]Build the Subsequences 生成子序列

[虚拟机OA]Group Anagram 变位词归类

[虚拟机OA]Maximal Square 最大正方形