코딩
[프로그래머스] 문자열압축 .py 본문
programmers.co.kr/learn/courses/30/lessons/60057
코딩테스트 연습 - 문자열 압축
데이터 처리 전문가가 되고 싶은 어피치는 문자열을 압축하는 방법에 대해 공부를 하고 있습니다. 최근에 대량의 데이터 처리를 위한 간단한 비손실 압축 방법에 대해 공부를 하고 있는데, 문자
programmers.co.kr
def solution(s):
min_length = len(s)
for parse in range(1, len(s)//2 + 1):
pre_word = s[:parse]
result = s[:parse]
cnt = 1
for i in range(parse, len(s), parse):
cur_word = s[i: i+parse]
if cur_word == pre_word:
cnt += 1
else:
if cnt == 1:
result += cur_word
else:
result += str(cnt) + cur_word
cnt = 1
pre_word = cur_word
if cnt > 1: # 마지막 문자열 처리
result += str(cnt)
min_length = min(min_length, len(result))
return min_length
'코딩테스트' 카테고리의 다른 글
[프로그래머스] 순위검색 .py (0) | 2021.02.23 |
---|---|
[프로그래머스] 괄호변환 .py (0) | 2021.02.23 |
[프로그래머스] 메뉴리뉴얼 .py (0) | 2021.02.21 |
[프로그래머스] 광고삽입 .py (0) | 2021.02.18 |
[프로그래머스] 합승택시요금 .py (0) | 2021.02.18 |
Comments