Created
February 27, 2020 06:28
-
-
Save inspirit941/29d9d07dce55bec82626e955c0d047a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(msg): | |
table = dict() | |
for idx, value in enumerate("ABCDEFGHIJKLMNOPQRSTUVWXYZ",1): | |
table[value] = idx | |
last_idx = idx | |
idx = 1 | |
answer = [] | |
letter = msg[0] | |
while idx < len(msg): | |
# 현재 입력 + 다음 글자 조합이 색인에 없는 경우 | |
if letter + msg[idx] not in table: | |
# 현재 입력을 answer 배열에 저장 | |
answer.append(table[letter]) | |
# 새 단어의 색인값 저장 | |
last_idx += 1 | |
table[letter + msg[idx]] = last_idx | |
# 현재 입력 = '다음 단어'로 저장 | |
letter = msg[idx] | |
# 다음 단어 | |
idx += 1 | |
continue | |
# 이미 색인되어 있는 단어의 경우, 다음 단어를 현재 입력에 추가 | |
letter += msg[idx] | |
idx += 1 | |
answer.append(table[letter]) | |
return answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment