38 ms python solution


  • 0
    Y
    class Solution(object):
        def countAndSay(self, n):
            """
            :type n: int
            :rtype: str
            """
            s = '1'
        
            
            for i in range(n-1):
                tmp = ''
                num = s[0]
                count = 1
                for j in range(1,len(s)):
                    if s[j]==num:
                        count+=1
                    else:
                        tmp += (str(count)+str(num))
                        count, num = 1, s[j]
                s = tmp+str(count)+str(num)
            return s

Log in to reply
 

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