码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode Count and Say

时间:2018-06-18 16:03:43      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:etc   sel   type   print   object   class   return   lse   solution   

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

标签:etc   sel   type   print   object   class   return   lse   solution   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!