https://programmers.co.kr/learn/courses/30/lessons/17684
코딩테스트 연습 - [3차] 압축
TOBEORNOTTOBEORTOBEORNOT [20, 15, 2, 5, 15, 18, 14, 15, 20, 27, 29, 31, 36, 30, 32, 34]
programmers.co.kr
# [3차]압축
dictionary = [0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
def solution(msg):
answer = []
checking_last_index = 0
while True:
str_to_check = msg[:checking_last_index + 1]
if str_to_check in dictionary:
if checking_last_index == len(msg) - 1:
answer.append(dictionary.index(str_to_check))
break
else:
answer.append(dictionary.index(str_to_check[:-1]))
dictionary.append(str_to_check)
msg = msg[checking_last_index:]
checking_last_index = 0
continue
checking_last_index += 1
return answer
'Problem-solving > 프로그래머스' 카테고리의 다른 글
프로그래머스 - (2019 카카오 개발자 겨울 인턴십) 크레인 인형뽑기 게임(Python3) (0) | 2020.08.01 |
---|---|
프로그래머스 - (2018 KAKAO BLIND RECRUITMENT) [3차] 파일명 정렬 (Python3) (0) | 2020.07.13 |
프로그래머스 - (2018 KAKAO BLIND RECRUITMENT) [3차] 방금그곡 (Python3) (2) | 2020.06.26 |
프로그래머스 - (2019 KAKAO BLIND RECRUITMENT) 후보키 (Python3) (0) | 2020.05.31 |
프로그래머스 - (2019 KAKAO BLIND RECRUITMENT) 오픈채팅방 (Python3) (0) | 2020.05.30 |
댓글