Medium
读题,获得一些线索
尝试求解
以上,AC!
python3
class Solution:
def numOfSubarrays(self, arr: List[int]) -> int:
presum = [0] * len(arr)
pre = 0
for i,v in enumerate(arr):
presum[i] = pre + v
pre = presum[i]
presum = [0] + presum
cnt1 = 0
cnt2 = 0
res = 0
for i in presum:
if i % 2 == 0:
cnt2 += 1
res += cnt1
else:
cnt1 += 1
res += cnt2
return res % (10**9+7)