[프로그래머스] 달리기 경주

단간단간·2024년 3월 28일
0

알고리즘 문제

목록 보기
25/106

python

def solution(players, callings):
    players_location = dict()

    players_location = {player: idx for idx, player in enumerate(players)}

    for calling_player in callings:
        calling_player_location = players_location[calling_player]
        forward_player = players[calling_player_location - 1]

        # 선수들 위치 변경
        players[calling_player_location] = forward_player
        players[calling_player_location - 1] = calling_player

        players_location[calling_player] -= 1
        players_location[forward_player] += 1

    return players
profile
simple is best

0개의 댓글