leetcode-python-外观数列

这题有点头疼

第一轮解法:暴力一轮轮计算

class Solution:
    def countAndSay(self, n: int) -> str:
        num = '1'
        r = 0 #轮数
        count=0 #统计数字个数
        now = '1'
        result = ''
        if n == 1:
            return num
    
        while(r < n-1):  
            r += 1
            for i in num:
                if i == now:
                    count +=1
                else:
                    result += str(count)+now
                    now = i
                    count = 1
            result += str(count) + now
            num = result
            result = ''
        
            count = 0
            now = num[0]
        return num

 

posted @ 2021-05-31 16:43  泊鸽  阅读(65)  评论(0)    收藏  举报