Java || DP || time O(n) || similar to the problem 940
\nclass Solution {\n    public int numberOfUniqueGoodSubsequences(String binary) {\n        int initialZeroCount= 0;\n        while(initialZeroCount < binary.le
```\nclass Solution {\n    public int numberOfUniqueGoodSubsequences(String binary) {\n        int initialZeroCount= 0;\n        while(initialZeroCount < binary.length() && binary.charAt(initialZeroCount) == \'0\') initialZeroCount++;\n        if(initialZeroCount == binary.length()) return 1;\n        long[] dp = new long[binary.length()];\n        dp[initialZeroCount] = 1;\n        int lastOne = 0, lastZero = 0;\n        long mod = (long) Math.pow(10, 9)+7;\n        for(int i=initialZeroCount+1;i<binary.length();i++){\n            int j = binary.charAt(i) == \'1\' ? lastOne : lastZero;\n            long dup = j > 0 ? dp[j-1] : 0;\n            dp[i] = 2 * dp[i-1] - dup;\n            if(dp[i] < 0) dp[i] += mod;\n            dp[i] %= mod;\n            if(binary.charAt(i) == \'0\') lastZero = i;\n            else lastOne = i;\n        }\n        \n        int hasZero = 0;\n        if(binary.contains("0")) hasZero = 1;\n        \n        \n        return (int) (dp[binary.length()-1] + hasZero);\n    }\n}\n```
['Dynamic Programming', 'Java']