C++ | DP Memorization | Very Simple Code
Please Upvote :)\n\n\nclass Solution {\npublic:\n    int mod=1000000007;\n    int countTexts(string pressedKeys) {\n        vector<int> dp(pressedKeys.size(),-1
Please Upvote :)\n\n```\nclass Solution {\npublic:\n    int mod=1000000007;\n    int countTexts(string pressedKeys) {\n        vector<int> dp(pressedKeys.size(),-1);\n        return fun(dp,pressedKeys,0);\n    }\n    long fun(vector<int>& dp,string& s,int i)\n    {\n        if(i>=s.length())\n            return 1;\n        \n        if(dp[i]!=-1)\n            return dp[i];\n        \n        int n=temp(s[i])-1;\n        long t=fun(dp,s,i+1)%mod;\n        for(int j=i+1;j<s.length();j++)\n        {\n            if(s[j]==s[i] && n)\n            {\n                n--;\n                t+=fun(dp,s,j+1)%mod;\n            }\n            else\n                break;\n        }\n        return dp[i]=t%mod;\n    }\n    int temp(char c)\n    {\n        if(c==\'7\'|| c==\'9\')\n            return 4;\n        return 3;\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C', 'C++']