Number of Sub-arrays With Odd Sum LeetCode solution in Python

1
class Solution:
2
def numOfSubarrays(self, arr: List[int]) -> int:
3
ce, co = 0, 0
4
s = 0
5
for x in arr:
6
if x % 2 == 0:
7
ce += 1
8
else:
9
old_co = co
10
co = ce + 1
11
ce = old_co
12

13
s += co
14

15
return s % (10**9 + 7)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0