class Solution:
def countAndSay(self, n):
"""
:type n: int
:rtype: str
1
11
21
1211
111221
"""
if n <= 0 or n % 1 != 0:
return '0'
if n == 1:
return '1'
rslt = "11"
while ( n > 2):
ans = rslt
rslt = ""
left = ans[0]
count = 1
for c in range(1,len(ans)):
if ans[c] == left:
count += 1
else:
rslt += str(count) + left
left = ans[c]
count = 1
rslt += str(count) + left
n -= 1
return rslt
这题目是不是有病啊。。