Python simple
Should be mostly self explanatory. \n\nLoop through the numbers, and when the number is the same as the last number, just keep a running total of one, two, thre
Should be mostly self explanatory. \n\nLoop through the numbers, and when the number is the same as the last number, just keep a running total of one, two, three, and four in a row. (Of course four in a row only exists for 7 or 9). \n\nWhen we have a new number, we sum up one, two, three, and four, and multiply that by our answer (ans) to keep a running total in ans. And at this point one = 1, all others are reset to 0.\n\nSee the code below:\n\n```\nclass Solution:\n    def countTexts(self, pressedKeys: str) -> int:\n        M = 10 ** 9 + 7\n        ans = one = 1\n        two = three = four = 0\n        last = \'\'\n        for x in pressedKeys:\n            if x == last:\n                one, two, three, four = one + two + three + four, one, two, three\n                if x not in \'79\':\n                    four = 0\n            else:\n                ans = ans * (one + two + three + four) % M\n                one = 1\n                two = three = four = 0\n            last = x\n        return ans * (one + two + three + four) % M\n\t\t```
[]