Easy solution | Dp | dynamic prorgramming | c++ | explanation | O(n)
\nclass Solution {\npublic:\n    int countTexts(string s) {\n        int n=s.length();\n        int mod=int(1e9)+7;\n        vector<int>dp(n,0);\n        unorde
```\nclass Solution {\npublic:\n    int countTexts(string s) {\n        int n=s.length();\n        int mod=int(1e9)+7;\n        vector<int>dp(n,0);\n        unordered_set<string>um;\n        for(int i=2;i<=9;i++){\n            string temp=to_string(i);\n            string cur=temp;\n            um.insert(cur);\n            cur+=temp;\n            um.insert(cur);\n            cur+=temp;\n            um.insert(cur);\n        }\n        um.insert("7777");\n        um.insert("9999");\n        \n        dp[0]=1;\n        if(n==1) return dp[0];\n        string cur=s.substr(0,2);\n        dp[1]=1;\n        if(um.find(cur)!=um.end()) dp[1]++;\n        if(n==2) return dp[1];\n        cur=s.substr(0,3);            \n        if(um.find(cur)!=um.end()) dp[2]++;\n        cur=s.substr(1,2);\n        if(um.find(cur)!=um.end()) dp[2]+=dp[0];\n        dp[2]+=dp[1];\n\n        for(int i=3;i<n;i++){\n            dp[i]=dp[i-1]%mod;\n            string cur1=s.substr(i-2,3);\n            if(um.find(cur1)!=um.end()) dp[i]=(dp[i-3]%mod+dp[i]%mod)%mod;\n            cur1=s.substr(i-1,2);\n            if(um.find(cur1)!=um.end()) dp[i]=(dp[i-2]%mod+dp[i]%mod)%mod;\n            if(s[i]==\'7\' || s[i]==\'9\'){\n                cur1=s.substr(i-3,4);\n                if(um.find(cur1)!=um.end()){\n                    if(i==3) dp[i]++;\n                    else dp[i]=(dp[i-4]%mod+dp[i]%mod)%mod;\n                } \n            }\n        }\n        \n        return dp[n-1]%mod;\n    }\n};\n```
['Dynamic Programming', 'C']