나의 풀이
import java.util.*;
class Solution {
public int[] solution(int[][] score) {
ArrayList<Integer> arr = new ArrayList<>();
for(int i=0; i<score.length; i++){
arr.add((score[i][0]+score[i][1]));
}
System.out.println("정렬 전= "+arr);
Collections.sort(arr, Collections.reverseOrder());
int[] answer =new int[score.length];
for(int i=0; i< score.length; i++){
answer[i]=arr.indexOf((score[i][0]+score[i][1]))+1;
}
return answer;
}
}
▶ 내림차순으로 정렬한 arr리스트의 index+1은 "등수를 나타낸다"
▶ 리스트를 오름차순으로 정렬한 다음에 list.IndexOf()를 이용해서 요소를 찾고
▶ index+1에서 answer배열에 그대로 갔다가 때려 박는다.
'프로그래머스(자바) > LV.0(자바)' 카테고리의 다른 글
로그인 성공?→ 행 인덱스 i를 이용해서 열(Column)로 접근한다!! (0) | 2022.11.27 |
---|---|
문자열 밀기★→ repeat()★, indexOf(), rotate() (0) | 2022.11.27 |
직사각형의 넓이 구하기 → 열(column)로 접근하고 싶은 경우★ (0) | 2022.11.27 |
외계어사전 → String[ ] 배열의 정렬, 문자열 내의 정렬★★ (0) | 2022.11.27 |
구슬을 나누는 경우의 수→순수(?) 조합 계산★★ (0) | 2022.11.27 |