51ms python solution


  • -2
    D

    `def countAndSay(self, n):

        if n ==1:
    
            return "1"
    
        a=self.countAndSay(n-1)
    
        s=""
    
        num = a[0]
    
        c=1
    
        for i in range(1,len(a)):
    
            if num != a[i]:
    
                s = s+(str(c) + num)
    
                num=a[i]
    
                c=1
    
            else:
    
                c+=1
    
        s = s + (str(c) + num)
    
        return s`

Log in to reply
 

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