Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return the researcher's h-index.
According to the definition of h-index on Wikipedia: The h-index is defined as the maximum value of h such that the given researcher has published at least h papers that have each been cited at least h times.
class Solution {
public int hIndex(int[] citations) {
ascending_sort(citations)
total = citations.length
max = 0
for(i = 0; i < total; i++)
citation = citations[i]
count = total - i
if(count >= citation)
max = citation
return max
}
}
citations = [100] 에서 틀렸다.
class Solution {
public int hIndex(int[] citations) {
int total = citations.length;
int max = 0;
Arrays.sort(citations);
for (int i = 0; i < total; i++) {
int citation = citations[i];
int count = total - i;
int result = Math.min(count, citation);
max = Math.max(max, result);
}
return max;
}
}
논문 개수와, 인용 숫자중에서 적은 값을 선택하였다.
public int hIndex(int[] citations) {
int n = citations.length;
int[] buckets = new int[n+1];
for(int c : citations) {
if(c >= n) {
buckets[n]++;
} else {
buckets[c]++;
}
}
int count = 0;
for(int i = n; i >= 0; i--) {
count += buckets[i];
if(count >= i) {
return i;
}
}
return 0;
}
정렬을 하지않고 푸는 방법도 있다.