38. Count and Say

Posted PirateLHX

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了38. Count and Say相关的知识,希望对你有一定的参考价值。

class Solution(object):
    def countAndSay(self, n):
        """
        :type n: int
        :rtype: str
        """
        s=[]
        for i in range(n):
            if i==0:
                s.append("1")
                #print 1
                continue
            test=s[i-1]
            flag=0
            count=0
            j=0
            tmp=‘‘
            while j<len(test):
                if(test[j]==test[flag]):
                    count+=1
                    j+=1
                    continue
                tmp=tmp+str(count)+test[flag]
                #s.append(tmp)
                #print tmp
                count=0
                flag=j
            if count>0:
                s.append(tmp+str(count)+test[flag])
            #print s
        return s[n-1]

  

以上是关于38. Count and Say的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode38. Count and Say

38. Count and Say - Unsolved

leetcode 38 Count and Say

38. Count and Say

38. Count and Say

38. Count and Say [easy] (Python)