Simple Python Solution


  • 0
    S
    class Solution(object):
        def countAndSay(self, n):
            """
            :type n: int
            :rtype: str
            """
            if n==0:return ""
            st="1"
            for k in range(1,n,1):
                i=0
                temp=""
                while i<len(st):
                    j=i+1
                    while j<len(st):
                        if st[j]!=st[i]:break
                        else: j+=1
                    temp+=(str(j-i)+str(st[i]))
                    i=j
                st=temp[:]
            return st

Log in to reply
 

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