Skip to content

Commit a45e6b0

Browse files
authored
Create 1524-number-of-sub-arrays-with-odd-sum.js
1 parent 1d02857 commit a45e6b0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {number[]} arr
3+
* @return {number}
4+
*/
5+
const numOfSubarrays = function(arr) {
6+
const n = arr.length, mod = 1e9 + 7
7+
8+
let oc = 0, ec = 1
9+
let sum = 0
10+
let res = 0
11+
for(let i = 0; i < n; i++) {
12+
sum += arr[i]
13+
if(sum % 2 === 1) {
14+
res += ec
15+
oc++
16+
} else {
17+
res += oc
18+
ec++
19+
}
20+
}
21+
22+
return res % mod
23+
};

0 commit comments

Comments
 (0)