leetcode Count and Say python

class Solution(object):
    def countAndSay(self, n):
        """
        :type n: int
        :rtype: str
        """
        s='1'
        for i in range(2,n+1):
            s=self.count(s)
        return s
    def count(self,s):
        t='';count=0;curr='#'
        for i in s:
            if i != curr:
                if curr != '#':
                    t+=str(count)+curr
                curr=i
                count=1
            else:
                count+=1
        t+=str(count)+curr
        return t

@link http://www.cnblogs.com/zuoyuan/p/3781329.html

posted @ 2015-12-20 13:50  hao.ma  阅读(133)  评论(0)    收藏  举报