Python easy to understand solution


  • 0
    J
    def countAndSay(self, n):
        if n <= 0: return ''
        s = '1'
        next = ""
        for j in range(1,n):
            count = 1
            for i in range(len(s)):
                if (i+1) < len(s) and s[i] == s[i+1]:
                    count +=1
                else:
                    next = next+str(count)+s[i]
                    count = 1
            s = next
            next = ""
        return s

Log in to reply
 

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