brute-force python3 solution


  • 0
    M

    simple brute-force method without groupby
    '''

    def countAndSay(self, n):
        if n<=0:
            return ""
        elif n==1:
            return "1"
    
        s="11"
        s1=""
    
        for i in range(2,n):
            count=0
            c_flag=s[0]
            while s!="":
                s_now=s[0]
                if c_flag==s_now:
                    count+=1
                else:
                    s1+=str(count)+c_flag
                    c_flag=s_now
                    count=1
                s=s[1:]
            s1+=str(count)+c_flag
            s=s1
            s1=""
    
        return s
    

    '''


Log in to reply
 

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