Straightforward C++ Memo Sol [HashSet to Store Valid Strings]
Use HashSet to store valid strings\ntime/space: O(n)\n\nclass Solution {\npublic:\n    int countTexts(string pressedKeys) \n    {\n        unordered_set<string>
Use HashSet to store valid strings\ntime/space: O(n)\n```\nclass Solution {\npublic:\n    int countTexts(string pressedKeys) \n    {\n        unordered_set<string> hs;\n        for (char c=\'2\'; c<=\'9\'; c++)\n        {\n            for (int i=1; i<=3; i++)\n            {\n                string temp(i, c);\n                hs.insert(temp);\n            }\n        }\n        hs.insert("7777");\n        hs.insert("9999");\n        int n = pressedKeys.size();\n        vector<int> memo(n, -1);\n        return helper(pressedKeys, hs, memo, 0);\n    }\nprivate:\n    int mod = (1e9)+7;\n    \n    int helper(string& pressedKeys, unordered_set<string>& hs, vector<int>& memo, int idx)\n    {\n        int n = pressedKeys.size(), res = 0;\n        if (idx == n) return 1;\n        if (memo[idx] != -1) return memo[idx];\n        for (int i=1; i<=4; i++)\n        {\n            if (idx+i <= n && hs.count(pressedKeys.substr(idx, i))) \n            {\n                res = (res%mod + helper(pressedKeys, hs, memo, idx+i)%mod)%mod;\n            }\n        }\n        return memo[idx] = res;\n    }\n};\n```
['Hash Table', 'Dynamic Programming', 'Memoization', 'C']