https://school.programmers.co.kr/learn/courses/30/lessons/142086
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
def solution(s):
answer = []
chr_dict = {}
for idx, chr_ in enumerate(s):
if chr_ not in chr_dict:
answer.append(-1)
chr_dict[chr_] = idx
else:
dist = idx - chr_dict[chr_]
answer.append(dist)
chr_dict[chr_] = idx
return answer
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[Python] 주차 요금 계산 (0) | 2023.01.21 |
---|---|
[Python] 연속 부분 수열 합의 개수 (0) | 2023.01.20 |
[Python] 오픈 채팅방 (1) | 2023.01.13 |
[Python] 피로도 (0) | 2023.01.12 |
[Python] 푸드 파이트 (0) | 2023.01.09 |