JAVA || DP
\nclass Solution {\n    public int countTexts(String pressedKeys) {\n        int n=pressedKeys.length();\n        \n        long [] dp = new long[n+1];\n       
```\nclass Solution {\n    public int countTexts(String pressedKeys) {\n        int n=pressedKeys.length();\n        \n        long [] dp = new long[n+1];\n        dp[0]=1;\n        dp[1]=1;\n        \n        for(int i=1;i<n;i++){\n            char ch=pressedKeys.charAt(i);\n            int j=i;\n            if(ch!=\'7\' && ch!=\'9\'){\n                while(j>0 && j>=i-2 && pressedKeys.charAt(j-1)==ch){\n                    dp[i+1] += dp[j]%1000000007;\n                    j--;\n                }\n                if(j!=i-3){\n                    dp[i+1]+=dp[j]%1000000007;\n                }\n            }else{\n                while(j>0 && j>=i-3 && pressedKeys.charAt(j-1)==ch){\n                    dp[i+1] += dp[j]%1000000007;\n                    j--;\n                }\n                if(j!=i-4){\n                    dp[i+1]+=dp[j]%1000000007;\n                }\n            }\n        }\n        return (int) (dp[n]%1000000007);\n    }\n}\n```
['Dynamic Programming', 'Java']