python solution


  • 0
    J

    '''

          class Solution:
                     def countAndSay(self, n):
                           seq='1'
                           for i in range(n-1):
                                new_seq=''
                                count=0
                                pre=0
                                for j in range(len(seq)):
                                    if j==0:
                                      pre=int(seq[j])
                                      count=1
                                   elif int(seq[j])!=pre:
                                        new_seq+=str(count)+str(pre)
                                        pre=int(seq[j])
                                        count=1
                                  else:
                                       count+=1
                
                        new_seq+=str(count)+str(pre)     
                        seq=new_seq
                        return seq  
    

    '''


Log in to reply
 

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