[Java] DP
\nclass Solution {\n    private static final int MOD = 1_000_000_007;\n    \n    public int countTexts(String passedKeys) {\n        int[] dp = new int[passedKe
```\nclass Solution {\n    private static final int MOD = 1_000_000_007;\n    \n    public int countTexts(String passedKeys) {\n        int[] dp = new int[passedKeys.length()+1];\n        dp[0] = 1;\n        \n        for(int i=1; i<=passedKeys.length(); i++){\n            char c = passedKeys.charAt(i-1);\n            \n            dp[i] += dp[i-1];\n            if(i >= 2 && passedKeys.charAt(i-1) == passedKeys.charAt(i-2)){\n                dp[i] = (dp[i] + dp[i-2])%MOD;\n            }\n            \n            if(i >= 3 && passedKeys.charAt(i-1) == passedKeys.charAt(i-2) && passedKeys.charAt(i-2) == passedKeys.charAt(i-3)){\n                dp[i] = (dp[i] + dp[i-3])%MOD;\n            }\n            \n            if(c == \'7\' || c == \'9\'){\n                if(i >= 4 && passedKeys.charAt(i-1) == passedKeys.charAt(i-2) && passedKeys.charAt(i-2) == passedKeys.charAt(i-3)\n                         && passedKeys.charAt(i-3) == passedKeys.charAt(i-4)\n                  ){\n                    dp[i] = (dp[i] + dp[i-4])%MOD;\n                }   \n            }\n        }\n        \n        return (int)(dp[passedKeys.length()]%MOD);\n    }\n}\n```
[]