-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgrammers_01.py
More file actions
44 lines (34 loc) · 1.17 KB
/
Programmers_01.py
File metadata and controls
44 lines (34 loc) · 1.17 KB
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
35
36
37
38
39
40
41
42
43
44
from collections import deque
def solution(s):
answer = 0
temp = []
mini = len(s)
for i in range(1,len(s)+1):
temp = deque(s[j : j+i] for j in range(0,len(s),i))
result = ""
while temp:
base = temp.popleft()
count = 1
if len(temp) < 1:
result += base
break
for k in range(len(temp)):
compare_str = temp.popleft()
if base == compare_str:
count += 1
else:
if count > 1:
result += (str(count) + base)
temp.appendleft(compare_str)
break
else:
result += base
temp.appendleft(compare_str)
break
if len(temp) < 1:
result += (str(count) + base)
break
if mini > len(result):
mini = len(result)
answer = mini
return answer