레벨2 문제
10/14 에 더럽게 품
from collections import deque
def solution(s):
answer = len(s)
# 자르는 개수
for i in range(1, len(s)//2+1):
news = deque(list(s))
temp = []
while news:
dummy = ''
for _ in range(1, i+1):
if (len(news) == 0):
break
num = news.popleft()
dummy += num
temp.append(dummy)
garbage = ''
cnt = 1
for i in range(1, len(temp)):
if temp[i-1] == temp[i]:
# 마지막이면
if ( i == len(temp)-1 ):
cnt += 1
garbage += str(cnt)
garbage += temp[i-1]
# 마지막이 아니면
else:
cnt += 1
else:
#마지막
if ( i == len(temp)-1 ):
if ( cnt == 1 ):
garbage += temp[i-1]
else:
garbage += str(cnt)
garbage += temp[i-1]
garbage += temp[i]
elif (cnt == 1):
garbage += temp[i-1]
else:
garbage += str(cnt)
garbage += temp[i-1]
cnt = 1
answer = min(answer, len(garbage))
return answer
def solution(s):
answer = len(s)
for i in range(1, (len(s)//2)+1 ):
word = ''
pivot = ''
cnt = 1
for j in range(0, len(s), i):
if ( s[j:j+i] == pivot ):
cnt += 1
else:
if (cnt != 1):
word += (str(cnt) + pivot)
else:
word += pivot
pivot = s[j:j+i]
cnt = 1
if (cnt != 1):
word = word + str(cnt) + pivot
else:
word = word + pivot
answer = min(answer, len(word))
return answer