본문으로 바로가기

2017 kakao blind recruitment 3차 압축

category 알고리즘 2019. 9. 5. 17:18
from collections import defaultdict
def solution(msg):
    answer = []
    
    msg = msg+'#'
    
    worddict = defaultdict(int)
    for idx in range(1, 27):
        worddict[chr(idx+64)] = idx
        
    k = 26  
    idx = 0
    maxwordlen = 1
    while msg[idx] != '#':
        for jdx in range(1, 1001):
            if worddict[msg[idx:idx+jdx]] == 0:
                answer.append(worddict[msg[idx: idx+jdx-1]])
                # print(msg[idx: idx+jdx-1], answer[-1])
                k += 1
                worddict[msg[idx: idx+jdx]] = k
                # print(msg[idx: idx+jdx], worddict[msg[idx: idx+jdx]])
                idx = idx+jdx-1
                break     
    
    return answer