Title: Given an array of citations (each citation was a non-negative integer) of a researcher, write a function to compute the RES Earcher ' s h-index.
According to the definition of H-index on Wikipedia: ' A scientist has index H if h of his/her N Papers has at least H citations each, and the other N? h Papers has no more than H citation S each. "
For example, given citations = [3, 0, 6, 1, 5] , which means the researcher have papers in total and each of 5 them had received 3, 0, 6, 1, 5 Citatio NS respectively. Since the researcher have papers with at least citations each and the remaining both with 3 3 no more than 3 CIT Ations each, he h-index is 3 .
Note:if there was several possible values h for, the maximum one is taken as the h-index.
Code:
public class Solution {public int hindex (int[] citations) { int n = citations.length, tot=0; int[] arr = new int[n+1]; for (int i=0; i<n; i++) { if (citations[i]>=n) arr[n]++; else arr[citations[i]]++; } for (int i=n; i>=0; i--) { tot + = arr[i]; if (tot>=i) return i; } return 0;} }
[Leetcode] 274. H-index Java