[프로그래머스] H-Index (Java)
https://school.programmers.co.kr/learn/courses/30/lessons/42747
입력 : 논문의 인용 횟수를 담은 배열
출력 : 논문의 H-Index
O(nlogn)
정렬
없음
없음
구현
import java.util.Arrays;
public class Solution {
public int solution(int[] citations) {
// Step 1: Sort the citations array
Arrays.sort(citations);
int n = citations.length;
int hIndex = 0;
// Step 2: Iterate over the sorted array from the end
for (int i = 0; i < n; i++) {
int h = n - i; // Number of papers with at least h citations
if (citations[i] >= h) {
hIndex = h;
break;
}
}
return hIndex;
}
}