1987. Number of Unique Good Subsequences

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1987

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