O(N) with detail explanation for DP
\n\n\n\n\nonly digit 7 and 9 has 4 consecutive press \nwhich we need to characters from i-3 , i-2, i-1 and i\nrest will be maximum 3 index characters from i-2,i
\n\n![image](https://assets.leetcode.com/users/images/a30713df-3f1e-4b26-96c5-8c5194e5d738_1651983880.0719159.png)\n\n\n**only digit 7 and 9 has 4 consecutive press \nwhich we need to characters from i-3 , i-2, i-1 and i\nrest will be maximum 3 index characters from i-2,i-1 and i**\n\n\n\n```\nlong M=(long)(1e9)+7;\n    String[] PAD=new String[]{"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};\n    public int countTexts(String s) {        \n        int n=s.length();\n        long[] res = new long[n];\n        res[0]=1;        \n        \n        for(int i=1;i<n;i++){\n             res[i]=res[i-1];             \n             res[i]%=M;\n            \n             if(i-1>=0 && s.charAt(i-1)==s.charAt(i)){\n                 res[i]+=i-2<0?1:res[i-2];            \n                 res[i]%=M;\n             }\n                        \n             if(i-2>=0 && s.charAt(i-2)==s.charAt(i-1) && s.charAt(i-1)==s.charAt(i)){\n                 res[i]+=i-3<0?1:res[i-3];                   \n                 res[i]%=M;\n             }            \n            \n            if(i-3>=0 && (s.charAt(i)==\'7\'||s.charAt(i)==\'9\') && s.charAt(i-3)==s.charAt(i-2) &&s.charAt(i-2)==s.charAt(i-1) && s.charAt(i-1)==s.charAt(i)){\n                res[i]+=i-4<0?1:res[i-4];\n                res[i]%=M;\n            }            \n        }        \n        return (int)res[n-1];\n        \n    }\n\n```
[]