Skip to content

Commit b444184

Browse files
authored
Update 2031-count-subarrays-with-more-ones-than-zeros.js
1 parent a854e29 commit b444184

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

2031-count-subarrays-with-more-ones-than-zeros.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ class FenwickTree {
2929
const subarraysWithMoreZerosThanOnes = function(nums) {
3030
const n = nums.length, mod = 1e9 + 7
3131
const bit = new FenwickTree(2 * n + 1)
32-
bit.update(n, 1)
32+
bit.update(n + 1, 1)
3333
let balance = 0, res = 0
3434
for(const e of nums) {
3535
balance += (e === 1 ? 1 : -1)
36-
bit.update(balance + n, 1)
37-
res = (res + bit.query(balance + n - 1)) % mod
36+
bit.update(balance + n + 1, 1)
37+
res = (res + bit.query(balance + n)) % mod
3838
}
3939

4040
return res

0 commit comments

Comments
 (0)