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))

猜你喜欢

转载自www.cnblogs.com/tonyzhong/p/9195282.html