码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-09-12 09:43:08      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:amp   思路   maximum   fun   elements   返回   题意   tor   and   

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个奇数的子数组

标签:amp   思路   maximum   fun   elements   返回   题意   tor   and   

原文地址:https://www.cnblogs.com/liuliu5151/p/11509812.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!