Python Solution | DP | O(n) Time | O(n) Space
\nclass Solution:\n    def countTexts(self, pressedKeys: str) -> int:\n        c = 0\n        prev = ""\n        dp = [0]*(len(pressedKeys)+1)\n        dp[0] = 
```\nclass Solution:\n    def countTexts(self, pressedKeys: str) -> int:\n        c = 0\n        prev = ""\n        dp = [0]*(len(pressedKeys)+1)\n        dp[0] = 1\n        for i in range(len(pressedKeys)):\n            if prev != pressedKeys[i]:\n                prev = pressedKeys[i]\n                c = 1\n                dp[i+1] = dp[i]\n            else:\n                c += 1\n                if pressedKeys[i] == \'7\' or pressedKeys[i] == \'9\':\n                    for j in range(min(4,c)):\n                        dp[i+1] += dp[i-j]\n                else:\n                    for j in range(min(3,c)):\n                        dp[i+1] += dp[i-j] \n        return dp[-1]%(10**9+7)\n```
['Dynamic Programming', 'Python']