Java memoziation based solution
\nclass Solution {\n    Integer[] cache;\n    int mod = (int)Math.pow(10,9) + 7;\n    public int countTexts(String pressedKeys) {\n        cache = new Integer[p
```\nclass Solution {\n    Integer[] cache;\n    int mod = (int)Math.pow(10,9) + 7;\n    public int countTexts(String pressedKeys) {\n        cache = new Integer[pressedKeys.length()];\n        return helper(pressedKeys, 0);\n    }\n    \n    int helper(String cur, int pos) {\n        if (pos >= cur.length()) {\n            return 1;\n        }\n        \n        if (cache[pos] != null) {\n            return cache[pos];\n        }\n        int count = 0;\n        for (int i = pos; i < cur.length() && i < pos + 4; i++) {\n            if (cur.charAt(i) == cur.charAt(pos)) {\n                count++;\n            } else {\n                break;\n            }\n        }\n        \n        if (cur.charAt(pos) == \'7\' || cur.charAt(pos) == \'9\') {\n    \n            count = count > 4 ? 4 : count;\n        } else {\n            count = count > 3 ? 3 : count;\n        }\n        \n        int res = 0;\n        \n\n        for (int i = pos; i < cur.length() && i < pos + count; i++) {\n            res += helper(cur, i+1);\n            res = res % mod;\n        }\n        return cache[pos] = res;\n    }\n}\n```
['Java']