【leetcode❤python】 38. Count and Say

AC代码:

class Solution(object):
    def countAndSay(self, n):
        """
        :type n: int
        :rtype: str
        """
        n=n-1
        if n==0:return str(1)
        tag=1;stri=str(11)
        while tag<n:
            cur=stri;j=0
            tmps=''
            while j<len(cur):
                count=1;m=j+1
                while m<len(cur):
                    if cur[j]==cur[m]:
                        count+=1;m+=1
                    else:break
                tmp=str(count)+str(cur[j])
                j=m

                tmps+=tmp
            stri=tmps;tag+=1
        return stri

 

posted @ 2016-10-25 21:06  火金队长  阅读(423)  评论(0编辑  收藏  举报