DP O(n) | O(1)
You just need to go through few examples to figure out the transition formula. Here is an example for "01011001":\n\n\n\nC++\ncpp\nint numberOfUniqueGoodSubsequ
You just need to go through few examples to figure out the transition formula. Here is an example for "01011001":\n\n![image](https://assets.leetcode.com/users/images/e3bd8928-39af-45eb-a053-ffcfd9191e46_1630214781.8356712.png)\n\n**C++**\n```cpp\nint numberOfUniqueGoodSubsequences(string binary) {\n    int mod = 1000000007, zeros = 0, ones = 0;\n    for (auto ch : binary)\n        if (ch == \'1\')\n            ones = (zeros + ones + 1) % mod;\n        else\n            zeros = (zeros + ones) % mod;\n    return (ones + zeros + (zeros || binary[0] == \'0\')) % mod;\n}  \n```
['C']