Python solution using re


  • 0
    H
     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(m.group(0))) + m.group(1),  res)
             return res

Log in to reply
 

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