Is this a slow solution? basically it "reads" the string , python


  • 0
    B
    class Solution:
    # @return a string
    def countAndSay(self, n):
        if n==0:
            return ''
        result='1'
        for i in range(1,n):
            count=1
            num=result[0]
            temp=[]
                
            for j in range(1,len(result)):
                if result[j]==num:
                    count=count+1
                else:
                    temp.append(str(count))
                    temp.append(num)
                    count=1
                    num=result[j]
                    
            temp.append(str(count))
            temp.append(num)
                    
            result=''.join(temp)
                    
        return result
    

    I see there are proofs that there can never be numbers >4 in the string... Anyway I didn't make use of any of those handsome arguments. So would this solution be considered too slow or dumb?

    thx...


Log in to reply
 

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