class Solution:
"""
@param n: the nth
@return: the nth sequence
"""
def countAndSay(self, n):
# write your code here
if n == 1:
return "1"
if n == 2:
return "11"
pre = self.countAndSay(n-1)
res = ""
count = 1
for i in range(len(pre)-1):
tmp = pre[i]
next = pre[i+1]
if tmp == next:
count += 1
else:
res = res + str(count) + str(tmp)
count = 1
res = res + str(count) + str(next)
return resPython, LintCode, 420. 报数
最新推荐文章于 2021-09-07 18:40:38 发布
3515

被折叠的 条评论
为什么被折叠?



