Re: [闲聊] 每日leetcode

楼主: DJYOMIYAHINA (通通打死)   2024-06-22 09:59:32
感觉很久没有写这类型的
卡卡怪怪的
点点点
def numberOfSubarrays(self, nums: List[int], k: int) -> int:
cnt_map, cnt, ans = defaultdict(int), 0, 0
cnt_map[0] = 1
for n in nums:
if n%2 == 1:
cnt+=1
cnt_map[cnt] += 1
ans += cnt_map[cnt-k]
return ans
作者: smart0eddie (smart0eddie)   2024-06-22 10:00:00
大师
作者: Furina (芙宁娜)   2024-06-22 10:20:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com