def solution(players, callings):
answer = []
index_player = {}
player_index ={}
for idx, val in enumerate(players, 1):
index_player[idx]=val
for idx, val in enumerate(players, 1):
player_index[val]=idx
for c in callings:
current_player = c
current_idx = player_index[c]
before_idx = current_idx-1
before_player = index_player[before_idx]
player_index[current_player], player_index[before_player] = before_idx, current_idx
index_player[current_idx], index_player[before_idx] = before_player, current_player
return list(index_player.values())
- 인덱스로 사람 찾아오기, 사람으로 인덱스 찾아오기를 하기 위해서 두개의 딕셔너리에 해당 정보를 넣어준뒤 시작한다.
- 시간초과 문제를 해결하기 위해서 두개의 딕셔너리에 해당하는 값들을 앞뒤로 순서 변경을 해주는 방식으로 진행
- li = list(dic.items()) 이거 시간 오래 걸리니까 바꾸지 말고 사용하시길