加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 07:47:23 所属栏目:Java 来源:网络整理
导读: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 e

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],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的个数

?

思路:

?

代码:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读