hashtable
class Solution:
def numWays(self, s: str) -> int:
histogram = defaultdict(lambda: 0)
counter = 0
for i in range(len(s)):
counter += 1 if s[i] == "1" else 0
histogram[counter] += 1
modNum = 10 ** 9 + 7
if counter == 0:
return (len(s) - 1) * (len(s) - 2) // 2 % modNum
if counter % 3 != 0:
return 0
else:
divided = counter // 3
return histogram[divided * 2] * histogram[divided] % modNumHash+Prefix
Reviewed
Todo
Last updated