python top down dp
\tclass Solution:\n\t\tdef countTexts(self, pressedKeys: str) -> int:\n\t\t\tmod = 10 ** 9 + 7\n\t\t\t@cache\n\t\t\tdef dfs(i):\n\t\t\t\tif i == 0:\n\t\t\t\t\tr
\tclass Solution:\n\t\tdef countTexts(self, pressedKeys: str) -> int:\n\t\t\tmod = 10 ** 9 + 7\n\t\t\t@cache\n\t\t\tdef dfs(i):\n\t\t\t\tif i == 0:\n\t\t\t\t\treturn 1\n\t\t\t\tcnt = dfs(i - 1)\n\t\t\t\tif i >= 2 and pressedKeys[i - 1] == pressedKeys[i - 2]:\n\t\t\t\t\tcnt += dfs(i - 2)\n\t\t\t\tif i >= 3 and pressedKeys[i - 3:i] == pressedKeys[i - 3] * 3:\n\t\t\t\t\tcnt += dfs(i - 3)\n\t\t\t\tif pressedKeys[i - 1] == "7" or pressedKeys[i - 1] == "9":\n\t\t\t\t\tif i >= 4 and pressedKeys[i - 4:i] == pressedKeys[i - 4] * 4:\n\t\t\t\t\t\tcnt += dfs(i - 4)\n\t\t\t\treturn cnt % mod\n\t\t\treturn dfs(len(pressedKeys)) % mod
[]