首页 > 其他 > 详细

Leetcode Count and Say

时间:2018-06-18 15:48:18      阅读:335      评论:0      收藏:0      [点我收藏+]
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

原文:https://www.cnblogs.com/tonyzhong/p/9195282.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!