class Solution(object):
def countAndSay(self, n):
"""
:type n: int
:rtype: str
"""
s = '1'
for _ in range(n1):
# count to remember current number frequency, temp to record the current step
count, current, temp = 0, s[0], ''
for ss in s:
if ss == current:
count += 1
else:
temp += (str(count) + current)
current = ss
count = 1
temp += (str(count) + current)
s = temp
return s
Straightforward python solution


@yuyuyu0905 said in Straightforward python solution:
def countAndSay(self, n): """ :type n: int :rtype: str """ s = '1' for _ in range(n1): # count to remember current number frequency, temp to record the current step count, current, temp = 0, s[0], '' for ss in s: if ss == current: count += 1 else: temp += (str(count) + current) current = ss count = 1 temp += (str(count) + current) s = temp return s