
class Solution(object):
def numberOfSubarrays(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: int
"""
def leK(nums, k):
start = 0
odd_count = 0
count = 0
for end in range(len(nums)):
if nums[end] % 2 == 1:
odd_count += 1
while odd_count > k:
if nums[start] % 2 == 1:
odd_count -= 1
start += 1
count += end-start+1
return count
return leK(nums, k) - leK(nums, k-1)
1246

被折叠的 条评论
为什么被折叠?



