반응형
from collections import Counter
def solution(players, callings):
play_check = {player: i for i, player in enumerate(players)}
idx_play_check = {i:player for i, player in enumerate(players)}
for data in callings:
# 현재 선수의 위치
now_idx = play_check[data]
# 현재 선수 앞의 선수 위치
pre_idx = now_idx-1
# 현재 선수가 앞에 등수로 바뀌고, 앞에 선수가 뒷 등수가 된다.
play_check[data] = pre_idx
play_check[idx_play_check[pre_idx]] = now_idx
idx_play_check[now_idx] = idx_play_check[pre_idx]
idx_play_check[pre_idx] = data
return list(idx_play_check.values())반응형
'삽집하는 개발들 > 알고리즘' 카테고리의 다른 글
| [10일차][프로그래머스][161990]바탕화면 정리 (0) | 2023.06.20 |
|---|---|
| [9일차][프로그래머스][2023 카카오 - 150370]개인정보 수집 유효성 검사 (0) | 2023.06.19 |
| [7일차][프로그래머스][172928]공원산책 (0) | 2023.06.14 |
| [6일차] [프로그래머스] [2022 카카오 - 92334]신고 결과 받기 (0) | 2023.06.12 |
| [5일차] [CodeUp] [기초 - 반복실행구조]basic_repetitive_execution (1) | 2023.06.11 |