My accepted python solution


  • 0
    B
    class Solution:                                         
    # @return a string                                  
    def countAndSay(self, n):                           
        prev='1'                                        
        for i in range(1,n):                            
            count = 0                                   
            now = ''                                    
            point_to = 0                                
            while count < len(prev):                    
                point_to = self.find(prev,prev[count],count)
                now+= str(point_to)                     
                now+= str(prev[count])                  
                count += point_to                       
            prev = now                                   
        return prev                                     
    def find(self,sour,res,i):                          
        while sour[i]!=res:                             
            i+=1                                        
        j=i                                             
        while j<len(sour) and sour[j] == res:           
            j+=1                                        
        return j-i

Log in to reply
 

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