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
❤leetcode,python2❤报数序列是指一个整数序列,按照其中的整数的顺序进行报数,得到下一个数
最新推荐文章于 2022-04-25 10:22:50 发布