반응형
programmers.co.kr/learn/courses/30/lessons/60057
풀긴 했지만 꽤 오래걸려서 실전이었으면 못 풀었을 것 같다...
def solution(s):
result = []
for unit in range(1, len(s) + 1): # unit(int) means the length of unit
length = 0
word = ''
show = 0
start = 0
for _ in range(len(s)//unit):
present = s[start:start+unit]
if word == present: # repeat
show +=1
if show == 2 :
length +=1
elif show > 2:
length -=len(str(show-1))
length += len(str(show))
elif word != present: # new word
word = present
show = 1
length += unit
start += unit
length += (len(s) % unit)
result.append(length)
return min(result)
댓글