2031. Count Subarrays With More Ones Than Zeros
Содержание
from sortedcontainers import SortedList
class Solution:
def subarraysWithMoreZerosThanOnes(self, nums: List[int]) -> int:
sl = SortedList([0])
mod = 10**9 + 7
res = s = 0
for x in nums:
s += x or -1
res += sl.bisect_left(s)
res %= mod
sl.add(s)
return res