Fastest solution in python with regular expression

  • 1
    class Solution:
        # @return a string
        def countAndSay(self,n):
            p = re.compile(r'(.)\1*')
            now = '1'
            for i in xrange(n-1):
                prev = now
                now = "".join( iter(  str(m.end()-m.start())+prev[m.start()] for m in re.finditer(p, prev)  ))
            return now

  • 0

    Hi..Would you mind sharing the run time for this in terms of ms.

Log in to reply

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