https://school.programmers.co.kr/learn/courses/30/lessons/178871
프로그램 제작자
코드 중심 개발자를 고용하십시오. 스택 기반 위치 일치. 프로그래머를 위한 개발자별 프로필에 가입하고 기술 호환성이 좋은 회사와 연결하십시오.
프로그래머.co.kr
문제를 풀다
간단한 질문인 것 같은데 Collection 스왑이나 일반 스왑 사용시 타임아웃 오류가 발생합니다.
프롬프트에서 지도로 해결해야 한다고 해서 거의 해결되지 않았습니다.
import java.util.*;
class Solution {
public String() solution(String() players, String() callings) {
Map<String, Integer> playerMap = new HashMap<>();
Map<Integer, String> rankMap = new TreeMap<>();
for (int i = 0; i < players.length; i++) {
playerMap.put(players(i),i+1); rankMap.put(i+1, players(i));
}
for (String s : callings) {
int tmp = playerMap.get(s); // 추월한 선수
String temp = rankMap.get(tmp-1); // 추월당한 선수
playerMap.put(s, tmp-1); playerMap.put(temp, tmp); // 갱신
rankMap.put(tmp-1, s); rankMap.put(tmp, temp); // 갱신
}
List<String> answer = new ArrayList<>();
for (int key : rankMap.keySet()) answer.add(rankMap.get(key));
return answer.toArray(new String(players.length));
}
}
RankMap은 TreeMap이 아닌 HashMap이 될 수 있지만 마지막에 한 번 더 정렬해야 하기 때문에 TreeMap으로 선언했습니다.
그러면 아무것도 없습니다.
두 맵에서 추월하는 플레이어와 추월하는 플레이어를 계속 업데이트하십시오.
이것은 좋은 질문입니다.
제 생각에는…
안녕 안녕 안녕