class Solution:
def countAndSay(self, n: int) -> str:
if n == 1:
return '1'
prev_solution = self.countAndSay(n-1)
res = ''
cur_num = None
counter = 0
for idx, num in enumerate(prev_solution):
if num != cur_num:
if cur_num is not None:
res += str(counter) + str(cur_num)
cur_num = num
counter = 1
else:
counter += 1
if idx == len(prev_solution)-1 and counter:
res += str(counter) + str(cur_num)
return res