Simple DP solution
\n\n# Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(n)\n Add your space complexity here, e.g. O(n) \n\n
\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int mod=1e9+7;\n    int dp[100000];\n    int solve(int index,string &str){\n        if(index>=str.size())\n            return 1;\n        \n        if(dp[index]!=-1)\n            return dp[index];\n        int ans=0;\n        if(str[index]==\'9\'||str[index]==\'7\'){\n            for(int i=index;i<str.size()&&i<index+4;i++){\n                if(str[i]!=str[index])\n                    break;\n                else\n                    ans=(ans%mod+solve(i+1,str)%mod)%mod;\n            }\n        }\n        \n        else{\n            \n             for(int i=index;i<str.size()&&i<index+3;i++){\n                if(str[i]!=str[index])\n                    break;\n                else\n                    ans=(ans%mod+solve(i+1,str)%mod)%mod;\n            }\n        }\n        \n        \n        return dp[index]=ans;\n            \n        }\n    \n    int countTexts(string pressedKeys) {\n        memset(dp,-1,sizeof(dp));\n        \n        return solve(0,pressedKeys);\n        \n        \n    }\n};\n```
['Dynamic Programming', 'C++']