38.Count and Say

 

 

class Solution:
    def countAndSay(self, n: int) -> str:
        if n == 1 :
            return "1"
        if n == 2:
            return "11"
        s = "11"
        for i in range(2,n):
            tmp_s = ""
            count = 1
            for j in range(len(s)-1):
                if s[j] == s[j+1]:
                    count += 1
                else:
                    tmp_s = tmp_s + str(count) + s[j]
                    count = 1
            s = tmp_s + str(count) + s[-1]
        return s    

 

posted @ 2020-05-09 15:17  星海寻梦233  阅读(146)  评论(0编辑  收藏  举报