1987. Number of Unique Good Subsequences
On This Page
class Solution:
def numberOfUniqueGoodSubsequences(self, binary: str) -> int:
f = g = 0
res = 0
mod = 10**9 + 7
for c in binary:
if c == "0":
g = (g + f) % mod
res = 1
else:
f = (f + g + 1) % mod
res = (res + f + g) % mod
return res