记载出现从头到目前为止出现t个奇数的个数
class Solution:
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
d = collections.defaultdict(int)
ans, t, d[0] = 0, 0, 1
for n in nums:
if n % 2 == 1:
t += 1
d[t] += 1
ans += d[t-k]
return ans