AC python solution


  • 0
    A
    class Solution(object):
        def countAndSay(self, n):
            """
            :type n: int
            :rtype: str
            """
            i  = 0
            seq = '1'
            string = ''
            result = ['1']
            
            while i < n:
                count = 1
                for j in range(1, len(seq)):
                    if seq[j] == seq[j - 1]:
                        count += 1
                    else:
                        string += str(count) + seq[j - 1]
                        count = 1
                        
                seq = string + str(count) + seq[-1]
                result.append(seq)
                string = ''
                i += 1
            
            return ''.join(result[n - 1])
    

Log in to reply
 

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