등수 매기기

문제


나의 생각

등수를 비교 할 수 있는 자료구조로 List로 지정하고 순위를 정하는 방식은 indextOf 함수를 이용하여 지정하는 방식으로 접근.


나의 답안

public static int[] solution(int[][] score) {
    List<Integer> scoreList = new ArrayList<>();
    for(int[] t : score){
        scoreList.add(t[0] + t[1]);
    }

    scoreList.sort(Collections.reverseOrder());

    int[] answer = new int[score.length];
    for(int i=0; i<score.length; i++){
        answer[i] = scoreList.indexOf(score[i][0] + score[i][1])+1;
    }

    return answer;
}

 

'Programmers 문제풀이 > Lv.0' 카테고리의 다른 글

겹치는 선분의 길이  (0) 2023.03.10
문자열 밀기  (0) 2023.03.10
OX퀴즈  (0) 2023.03.08
치킨 쿠폰  (0) 2023.03.08
로그인 성공?  (0) 2023.03.08