Topic:
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. accordingto the definition of H-index on Wikipedia: ' A scientist has index h if h of his/her N papers having at Le AST h citations each, and the other n−h papers has no more than H citations each. " = [3, 0, 6, 1, 5], which means the researcher have 5 papers in total and each of them had received 3, 0, 6, 1, 5 C Itations respectively. Since the researcher have 3 papers with at least 3 citations each and the remaining both with no more than 3 citations each, His h-index are 3 for H, and the maximum one is taken as the h-index.
Analysis: With a hash table (auxiliary array), the time complexity is O (N). After constructing the auxiliary array, the traversal begins after the array, and if the total number of paper >= the number of references, the reference number is returned.
The Java code is as follows:
Public intHindex (int[] citations) { int[] tmp =New int[Citations.length + 1]; for(inti = 0; i < citations.length; i++) { if(Citations[i] >=citations.length) {Tmp[citations.length]++; } Else{Tmp[citations[i]]++; } } intsum = 0; for(inti = tmp.length-1; I >= 0; i--) {sum+=Tmp[i]; if(Sum >=i) {returni; } } return0; }
H-index (Hash Table)