inblog logo
|
stupefyee
    알고리즘문제풀기

    [JAVA 문제 풀이] 323. 달리기 경주

    프로그래머스 (178871)
    Stupefyee's avatar
    Stupefyee
    Jun 17, 2025
    [JAVA 문제 풀이] 323. 달리기 경주
    Contents
    내가 작성한 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/178871
    notion image
     

    내가 작성한 코드

    import java.util.*; class Solution { public String[] solution(String[] players, String[] callings) { Map<String, Integer> idxMap = new HashMap<>(); // 선수 이름 → 현재 인덱스 for (int i = 0; i < players.length; i++) { idxMap.put(players[i], i); } for (String calling : callings) { int idx = idxMap.get(calling); // 현재 위치 String front = players[idx - 1]; // 앞자리 선수 이름 players[idx - 1] = calling; // 현재 선수 이름을 앞자리로 이동 players[idx] = front; // 앞자리 선수를 현재 선수 위치로 이동 // Map의 인덱스도 같이 갱신 idxMap.put(calling, idx - 1); idxMap.put(front, idx); } return players; } }
    Share article
    Contents
    내가 작성한 코드

    stupefyee

    RSS·Powered by Inblog