I don't know why, but i understood this question easily. Here is my solution.


  • 0
    H

    class Solution(object):
    def countAndSay(self, n):
    """
    :type n: int
    :rtype: str
    """

        res="1"
        res1=""
        iter = 0
        while iter < n-1:
            index = 0
            count = 1
            while index + 1 < len(res):
                if res[index+1] == res[index]:
                    count = count + 1
                    index = index + 1
                else:
                    res1 = res1 + "%d%s" % (count, res[index])
                    count = 1
                    index = index + 1
            else:
                res1 = res1 + "%d%s" % (count, res[index])
            iter = iter + 1
            res = res1
            print res
            res1 = ""
         
        return res

Log in to reply
 

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