class Solution:
def recursive(self, n) :
if n == 1 :
return "1"
arr = self.recursive(n-1)
count, check = 0, 0
temp = []
for j in arr :
if count == 0 :
check,count = j,1
elif check == j :
count += 1
else :
temp.append(str(count)+str(check))
count, check = 1, j
temp.append(str(count)+str(j))
return "".join(temp)
def countAndSay(self, n: int) -> str:
return self.recursive(n)
문제정리
Given an integer n, return the nth term of the Count-and-Say sequence using run-length encoding(RLE) on the previous term.
풀이과정
Use recursion to generate the current term by applying run-length encoding to the previous term.
by applying은 “~을 적용함으로써”
풀이 후
This solution could be cleaner. I need to improve my programming skills.
could be cleaner는 직역하면 “더 깔끔할 수 있다”