쉬워보이지만, 이런 문제는 집중력이 필요하다. 숫자값을 문자를 * 를 이용하여 곱할수 있다는것을 배웠다.
def runLengthEncoding(string):
result = ""
currChar = string[0]
counter = 1
for index in range(1, len(string)+1):
if index < len(string) and currChar == string[index]:
counter += 1
else:
#break and add to result
div = counter // 9
remain = counter % 9
#int * "9" = int * 9
result += div * ('9' + currChar)
if remain > 0:
result += str(remain) + currChar
if index <= len(string)-1:
currChar= string[index]
counter = 1
return result