[프로그래머스]sorting-H-index

snusun·2021년 1월 10일
0

The method sort(int[]) in the type Arrays is not applicable for the arguments (int[], Collections.reverseOrder())

내림차순으로 sort할 때 다음과 같은 에러가 발생했는데, https://hogu-programmer.tistory.com/32를 보고 해결하였다.

알고리즘은 다음을 따랐다.

h-index 산출 방법
1. 논문을 피인용횟수가 많은 순으로 정렬한다.
2. 논문의 번호와 피인용횟수를 비교하여 피인용횟수가 논문의 번호와 같거나 큰 번호가 연구자의 h-index가 된다.

import java.util.Arrays;
import java.util.Collections;

class Solution {
    public int solution(int[] citations) {
        int answer = 0;
        Integer[] c = new Integer[citations.length];
        for(int i=0; i<citations.length; i++){
            c[i] = new Integer(citations[i]);
        }
        Arrays.sort(c, Collections.reverseOrder());
        for(int i=0; i<c.length; i++){
            if(i+1 <= c[i]){
                answer++;
            } else break;
        }
        return answer;
    }
}
profile
대학생 근데 이제 컴공을 곁들인

0개의 댓글