[Version]
⦁ 2024.04.03 / [Algorithm / Programmers] 달리기 경주
import java.util.*;
class Solution {
public String[] solution(String[] players, String[] callings) {
Map<String, Integer> playerIndices = new HashMap<>();
for (int i = 0; i < players.length; i++) {
playerIndices.put(players[i], i);
}
for (String calling : callings) {
int index = playerIndices.get(calling);
String tempPlayer = players[index - 1];
players[index - 1] = players[index];
players[index] = tempPlayer;
playerIndices.put(players[index - 1], index - 1);
playerIndices.put(players[index], index);
}
return players;
}
}
'Algorithm > 프로그래머스' 카테고리의 다른 글
[Algorithm / Programmers] 바탕화면 정리 (0) | 2024.04.03 |
---|---|
[Algorithm / Programmers] 2023 KAKAO BLIND RECRUITMENT-개인정보 수집 유효기간 (0) | 2024.04.03 |
[Algorithm / Programmers] 숫자의 표현 (0) | 2024.04.03 |
[Algorithm / Programmers] 다음 큰 숫자 (0) | 2024.04.03 |
[Algorithm / Programmers] 2019 카카오 개발자 겨울 인턴십 - 크레인 인형뽑기 게임 (0) | 2024.04.02 |