C++ || DP || O(n) time
\nclass Solution {\npublic:\n    int M=1e9+7;\n    int countTexts(string s) {\n        int n=s.size();\n        vector<long long> dp(n+1);\n        dp[0]=1;\n  
```\nclass Solution {\npublic:\n    int M=1e9+7;\n    int countTexts(string s) {\n        int n=s.size();\n        vector<long long> dp(n+1);\n        dp[0]=1;\n        for(int i=1;i<=n;i++){\n            //firstly if character is same or different then copy last value.\n            dp[i]=dp[i-1];\n            //if last two characters are same then also last that value.\n            if((i-2)>=0 && s[i-1]==s[i-2])\n                dp[i]=(dp[i]+dp[i-2])%M;\n            else\n                continue;\n            //if last 3 characters are same then also add that value.\n            if((i-3)>=0 && s[i-1]==s[i-3])\n                dp[i]=(dp[i]+dp[i-3])%M;\n            else\n                continue;\n            //if we have 7 or 9 as characters we have to also check for 4th character.\n            if((s[i-1]==\'7\' || s[i-1]==\'9\') && (i-4)>=0 && s[i-1]==s[i-4])\n                dp[i]=(dp[i]+dp[i-4])%M;\n        }\n        return dp[n]%M;\n    }\n};\n```
['Dynamic Programming', 'C']