문제: https://school.programmers.co.kr/learn/courses/30/lessons/142086
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
python 풀이 코드
def solution(s: str) -> list:
char_locations = dict()
answer = []
for idx, c in enumerate(s):
if c in char_locations:
answer.append(idx - char_locations[c])
else:
answer.append(-1)
char_locations[c] = idx
return answer
print(solution("banana")) # 정답: [-1, -1, -1, 2, 2, 2]
'코딩테스트 준비 (알고리즘 & SQL) > 문자열 문제' 카테고리의 다른 글
[프로그래머스] 푸드 파이트 대회 (python) (0) | 2024.08.17 |
---|---|
[프로그래머스] 문자열 내 마음대로 정렬하기 (python) (0) | 2024.08.17 |
[프로그래머스] 숫자 문자열과 영단어 (python) (0) | 2024.08.17 |
[프로그래머스] 시저 암호 (Python) (0) | 2024.08.15 |
[프로그래머스] 크기가 작은 부분문자열 (Python) (0) | 2024.08.14 |