문제
내가 작성한 정답
class Solution {
public int[] solution(int[][] score) {
int len = score.length;
int[] answer = new int[len];
double[] avg = new double[len];
for(int i=0; i<len; i++){
avg[i] = (double) (score[i][0] + score[i][1])/2;
}
for(int i=0; i<len; i++){
int rank = 1;
for(double d:avg){
if(avg[i]<d) rank++;
}
answer[i] = rank;
}
return answer;
}
}다른 사람들의 정답
import java.util.*;
class Solution {
public int[] solution(int[][] score) {
List<Integer> scoreList = new ArrayList<>();
for(int[] t : score){
scoreList.add(t[0] + t[1]);
}
scoreList.sort(Comparator.reverseOrder());
int[] answer = new int[score.length];
for(int i=0; i<score.length; i++){
// indexOf가 첫번째 인덱스를 반환하기 때문에 중복도 ㅇㅋ
answer[i] = scoreList.indexOf(score[i][0] + score[i][1])+1;
}
return answer;
}
}Share article