https://school.programmers.co.kr/learn/courses/30/lessons/142086
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
def solution(s):
answer = []
alp_dict = {}
for i, alp in enumerate(s):
if alp not in alp_dict.keys():
answer.append(-1)
else:
answer.append(i - alp_dict[alp])
alp_dict[alp] = i # 해당 알파벳이 등장한 가장 최근 인덱스를 저장
return answer
'Coding Test Practice > Python' 카테고리의 다른 글
[프로그래머스 코딩테스트 연습 Lv. 1] 명예의 전당 (1) (0) | 2023.03.13 |
---|---|
[프로그래머스 코딩테스트 연습 Lv. 1] 문자열 나누기 (1) | 2023.03.13 |
[프로그래머스 코딩테스트 연습 Lv. 1] 문자열 나누기 (0) | 2023.03.13 |
[프로그래머스 코딩테스트 연습 Lv. 1] 크키가 작은 부분 문자열 (0) | 2023.03.13 |
[프로그래머스 코딩테스트 연습 Lv. 1] 개인정보 수집 유효기간 (0) | 2023.03.13 |