My naive Python Simulation Solution


  • 0
    class Solution(object):
        def countAndSay(self, n):
            ans = '1'
            for i in xrange(n - 1):
                digit, tmp, cnt = ans[0], '', 0
                for j in xrange(len(ans)):
                    if ans[j] == digit:
                        cnt += 1
                    else:
                        tmp += str(cnt) + digit
                        digit, cnt = ans[j], 1
                ans = tmp + str(cnt) + digit
            return ans
    

Log in to reply
 

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