-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode16.py
More file actions
33 lines (29 loc) · 901 Bytes
/
code16.py
File metadata and controls
33 lines (29 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#출처 https://school.programmers.co.kr/learn/courses/30/lessons/60057
#문제 코딩테스트 연습 2020 KAKAO BLIND RECRUITMENT 문자열 압축
def solution(s):
max_cnt = int(len(s) / 2)
target = []
if len(s) ==1:
return s
for i in range(1, max_cnt +1):
answer = ''
recursive = 0
pre = ''
for j in range(0, len(s), i):
cur = s[j:j+i]
if (pre != cur):
recursive = 0
answer += cur
pre = cur
else:
recursive += 1
answer = answer[:len(answer) - i]
if recursive > 1:
answer = answer[: -len(str(recursive))]
answer += "{}{}".format(recursive + 1, cur)
target.append(len(answer))
return min(target)
a = solution("a")
print(a)
# s = 'dsafdsa'
# print(s[-1])