관리 메뉴

여름 언덕에서 배운 것

[0단계/1점]진료 순서 정하기 본문

가랑비에 옷 젖는 줄 모른다 💻/🌰코테문풀_꾸준히

[0단계/1점]진료 순서 정하기

잔뜩 2025. 3. 5. 14:51
import java.util.*;
class Solution {
    public int[] solution(int[] emergency) {
        int[] answer = new int[emergency.length];
        int[] copyArray = Arrays.copyOf(emergency,emergency.length);
        Arrays.sort(copyArray);
        
        Map<Integer,Integer> ranking = new HashMap<>();
        
        for(int i=0;i<copyArray.length;i++){
            ranking.put(copyArray[i],copyArray.length-i);
        }
        for(int j=0;j<copyArray.length;j++){
            answer[j] = ranking.get(emergency[j]);
        }
        return answer;
    }
}

Arrays.copyOf랑 sort 이용 !

728x90