Scala DP end with 0 and end with 1
\nobject Solution {\n    // Memory Limit Exceeded on "111001101100000001001110110101110001100"\n    def numberOfUniqueGoodSubsequencesBad0(binary: String): Int 
```\nobject Solution {\n    // Memory Limit Exceeded on "111001101100000001001110110101110001100"\n    def numberOfUniqueGoodSubsequencesBad0(binary: String): Int = {\n        var seen=scala.collection.mutable.Set[Int]()\n        var num=0\n        var mod=math.pow(10,9)+7\n        def ps(i:Int,num:Int,firstChar:Char=0) : Unit = { //math.pow(2,31)-1-1e9>=0\n           if (i==binary.size) {if  (firstChar!=0) seen += num}\n           else {\n               if (firstChar!=\'0\')   ps(i+1,num<<1|binary(i)-\'0\',firstChar.max(binary(i)))\n               ps(i+1,num,firstChar)\n           }\n        }\n        ps(0,0)\n        (seen.size)%mod.toInt\n    }\n\t\n\t//DP iterative, break down by ending with 0 or 1, \n    def numberOfUniqueGoodSubsequences(binary: String): Int = {\n        // a power set is the accumulated/running set of all previous sets plus appended current element to previous set (without and without current elemement)\n        var zeroes,ones,total=0\n        val mod=(1e9+7).toInt\n        for (c <- binary) {\n            if (c==\'1\') ones=(ones+zeroes+1)%mod\n            else zeroes= (zeroes+ones)%mod\n        }\n        (ones+zeroes+(if (binary.contains(\'0\')) 1 else 0))%mod\n    }\n}\n```
[]