Skip to content

Commit

Permalink
6/28 문자열 압축
Browse files Browse the repository at this point in the history
  • Loading branch information
ChoiEungi committed Jun 29, 2021
1 parent b0404c8 commit 7f63bba
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
19 changes: 19 additions & 0 deletions choieungi/12-9 문자열 압축.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def solution(s):
answer = len(s)
l = len(s)
for step in range(1, l // 2 + 1):
cnt = 1
compressed = ""
prev = s[0:step]
for i in range(step, l, step):
if s[i:i + step] == prev:
cnt += 1
else:
compressed += str(cnt) + prev if cnt > 1 else prev
prev = s[i: i + step]
cnt = 1
compressed += str(cnt) + prev if cnt > 1 else prev

answer = min(answer, len(compressed))

return answer
Empty file added choieungi/TeamNote/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions choieungi/TeamNote/rotate_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# rotate left n*m array

def rotate(space, n, m):
new_space = [[0]*m for _ in range(n)]

for i in range(n):
for j in range(m):
new_space[n-j-1][i] = space[i][j]
return new_space


test_space = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]

return_val = rotate(test_space,len(test_space), len(test_space[0]))

for i in return_val:
print (i)
"""
[3, 6, 9]
[2, 5, 8]
[1, 4, 7]
"""
22 changes: 19 additions & 3 deletions choieungi/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
s = [*map(int, input())]
l = len(s)//2
print("READY"if sum(s[:l])-sum(s[l:])else"LUCKY")
def solution(s):
answer = len(s)
l = len(s)
for step in range(1, l // 2 + 1):
cnt = 1
compressed = ""
prev = s[0:step]
for i in range(step, l, step):
if s[i:i + step] == prev:
cnt += 1
else:
compressed += str(cnt) + prev if cnt > 1 else prev
prev = s[i: i + step]
cnt = 1
compressed += str(cnt) + prev if cnt > 1 else prev

answer = min(answer, len(compressed))

return answer

0 comments on commit 7f63bba

Please sign in to comment.