Skip to content

Commit 56753cf

Browse files
committed
1524
1 parent 612ecf9 commit 56753cf

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# @param {Integer[]} arr
2+
# @return {Integer}
3+
def num_of_subarrays(arr)
4+
mod = 1000000007
5+
count = 0
6+
odd_count = 0
7+
even_count = 0
8+
sum = 0
9+
arr.each { |x|
10+
sum += x
11+
if sum.odd?
12+
odd_count += 1
13+
count += even_count + 1
14+
else
15+
even_count += 1
16+
count += odd_count
17+
end
18+
count %= mod
19+
}
20+
21+
count % mod
22+
end

0 commit comments

Comments
 (0)