[Java] O(n) DP
keep a trailing count of repeated digit:\n- if count <= string length of that digit (4 for \'7\' and \'9\', 3 for the rest): cur = prev * 2\n- if count > string
keep a trailing count of repeated digit:\n- if count <= string length of that digit (4 for \'7\' and \'9\', 3 for the rest): cur = prev * 2\n- if count > string length: iterate and add the previous slots (4 for \'7\' and \'9\', 3 for the rest)\n- reset when passing to a different digit\n\n```\nclass Solution {\n    public int countTexts(String keys) {\n        int mod = 1000000007, n = keys.length();\n        int[] dp = new int[n];\n        int count = 1;\n        dp[0] = 1;\n        for (int i = 1; i < n; i++) {\n            if (keys.charAt(i) == keys.charAt(i - 1)) {\n                int val = keys.charAt(i) - \'0\';\n                int c = (val == 7 || val == 9) ? 4 : 3;\n                count++;\n                if (count <= c) dp[i] = (int) ((long) dp[i - 1] * 2 % mod);\n                else {\n                    for (int k = 1; k <= c; k++) {\n                        dp[i] = (int) (((long) dp[i] + dp[i - k]) % mod);\n                    }\n                }\n            }\n            else {\n                count = 1;\n                dp[i] = dp[i-1];\n            }\n        }\n        return dp[n - 1];\n    }\n}\n```
['Dynamic Programming', 'Java']