Simple python solution


  • 0
    L
    class Solution(object):
        def countAndSay(self, n):
            """
            :type n: int
            :rtype: str
            """
            temp = str(1)
            for _ in range(0,n-1,1):
                temp = self.cs(temp)
            return temp
        
        def cs(self,temp):
            res=''
            i=0
            while i < len(temp):
                count = 1
                while (i+1) < len(temp) and temp[i]==temp[i+1]:
                    count+=1
                    i+=1
                res += (str(count)+temp[i])
                i+=1
            return res
    

Log in to reply
 

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