Python solution using re

  • 0
     class Solution(object):
         def countAndSay(self, n):
             :type n: int
             :rtype: str
             import re
             pat = re.compile(r"(\d)(\1*)")
             res = "1"
             for i in range(n - 1):
                 res = pat.sub(lambda m: str(len( +,  res)
             return res

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.