版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_22795513/article/details/80655700
class Solution(object):
def countAndSay(self, n):
"""
:type n: int
:rtype: str
"""
old = '1'
for i in range(n-1):
num = 1
value = ''
next = ''
while 1:
try:
if old[0]==old[1]:
num += 1
value = old[0]
else:
if value!='':
next+= str(num)+str(value)
else:
next+= str(num)+str(old[0])
num = 1
value = ''
old=old[1:]
except IndexError,e:
next += str(num)+str(old[0])
old = next
break
return old