-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompress_string.py
More file actions
34 lines (27 loc) · 842 Bytes
/
compress_string.py
File metadata and controls
34 lines (27 loc) · 842 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
34
# 프로그래머스 코딩테스트 - 문자열 압축(Lv2)
def solution(s):
length = len(s)
s_zip = ''
zip_list =[]
if length == 1:
return 1
for i in range(1, length):
sentence = s[:i]
count = 1
for j in range(i, length, i):
if s[j:j+i] == sentence:
count += 1
else :
if count == 1:
s_zip += sentence
sentence = s[j:j+i]
else:
s_zip += str(count) + sentence
sentence = s[j:j+i]
count = 1
if count == 1:
s_zip += str(count) + sentence
sentence = s[j:j+i]
zip_list.append(len(s_zip))
s_zip = ''
return min(zip_list)