취준시절/프로그래머스

[프로그래머스] 2018 KAKAO BLIND RECRUITMENT - [3차] 압축

MAYMIN 2021. 9. 10. 15:09
728x90
SMALL

이건 배열 슬라이싱만 잘 활용한다면 쉬운 문제 :)  

카카오 문제 재밌다 ㅎㅎㅎㅎㅎ 구웃

 

그리고 나는 dictionary라는 배열에 A ~ Z까지 넣어 초기화 해준 다음, index값에 접근하여 해당 값을 answer에 넣어주었다. !!

def solution(msg):
    answer = []
    dictionary = [chr(i) for i in range(65,91)]
    w=0
    for c in range(len(msg)+1):
        current = msg[w:c]
        if c ==len(msg):
            answer.append(dictionary.index(current)+1)
            break
        wc = msg[w:c+1]
        if wc not in dictionary:
            dictionary.append(wc)
            answer.append(dictionary.index(current)+1)
            w=c
        else:
            continue

    return answer
728x90
LIST