S E P H ' S

[Python] 압축 본문

Algorithm/Programmers

[Python] 압축

yoseph0310 2021. 8. 26. 17:18
 

코딩테스트 연습 - [3차] 압축

TOBEORNOTTOBEORTOBEORNOT [20, 15, 2, 5, 15, 18, 14, 15, 20, 27, 29, 31, 36, 30, 32, 34]

programmers.co.kr

문제보기

 

def solution(msg):
    answer = []
    dic = {}
    for i in range(26):
        dic[chr(65+i)] = i + 1
    
    w, c = 0, 0
    while True:
        c += 1
        if c == len(msg):
            answer.append(dic[msg[w:c]])
            break
        if msg[w:c+1] not in dic:
            dic[msg[w:c+1]] = len(dic) + 1
            answer.append(dic[msg[w:c]])
            w = c
    return answer

'Algorithm > Programmers' 카테고리의 다른 글

[Python] 방문 길이  (0) 2021.08.26
[Python] 방금그곡  (0) 2021.08.26
[Python] 파일명 정렬  (0) 2021.08.25
[Python] 124 나라의 숫자  (0) 2021.08.25
[Python] 소수 찾기  (0) 2021.08.25