Leetcode Count and Say
Posted tonyzhong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode Count and Say相关的知识,希望对你有一定的参考价值。
class Solution(object):
def countAndSay(self, n):
"""
:type n: int
:rtype: str
"""
s = "1"
for i in range(0,n-1):
current = ""
count = 0
ctstr = ""
for j in s:
if ctstr == j:
count += 1
else:
if count != 0:
current += str(count) + ctstr
count = 1
ctstr = j
else:
count = 1
ctstr = j
current += str(count) + ctstr
s = current
return s
solution = Solution()
print(solution.countAndSay(5))
以上是关于Leetcode Count and Say的主要内容,如果未能解决你的问题,请参考以下文章
LeetCode题意分析&解答38. Count and Say