가장 가까운 같은 글

NJW·2023년 6월 3일
0

코테

목록 보기
168/170
def solution(s):
    answer = []
    words = {}
    
    for i in range(len(s)):
        current = s[i]
        if current in words:
            # 만일 해당 문자가 dict에 있다.
            answer.append((i-words[current]))
            words[current] = i
        else:
            # 처음 나온 문자다.
            answer.append(-1)
            words[current] = i
    
    return answer

더 자세한 설명은 내 티스토리에

https://jiwonna52.tistory.com/19

profile
https://jiwonna52.tistory.com/

0개의 댓글