practivceAlgorithm/programmers
[Programmers][Python] KAKAO 2018 압축
findTheValue
2021. 11. 4. 02:50
idx하나씩 늘려주며 문자열 사전에 추가하고 -1한 글자의 사전값은 answer에 추가
def solution(msg):
msg += '.'
answer = []
dic = {chr(i + ord('A')): i + 1 for i in range(26)}
idx, last_idx = 0, len(msg) - 1
new_hash = 27
while idx < last_idx:
start = msg[idx]
while idx < last_idx and start in dic:
idx += 1
start += msg[idx]
answer.append(dic[start[:-1]])
dic[start] = new_hash
new_hash += 1
return answer