274. H-Index
Input: citations = [3,0,6,1,5]
Output: 3
Explanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had
received 3, 0, 6, 1, 5 citations respectively.
Since the researcher has 3 papers with at least 3 citations each and the remaining
two with no more than 3 citations each, her h-index is 3.class Solution {
public int hIndex(int[] citations) {
//0 1 3 6 5
//0 1 2 3 4
if(citations == null || citations.length == 0)
return 0;
Arrays.sort(citations);
int size = citations.length;
int papers = 1;
for(int i = size -1 ; i >= 0;i--){
if(citations[i] < papers){
break;
}
papers++;
}
return citations[0] > size ? size : papers-1;
}
}Last updated