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.
is a quick row, but test instructions a bit vague, at least h citations does not necessarily mean that there must be equal to H citations, and the remaining n-h is no more than, that is, can exist equal to the situation.
voidSwap (intA[],intAintBB) { intTMP =A[a]; A[a]=A[b]; A[B]=tmp;}intPartition (int* Citations,intLeftintRight ) { intPivot =Citations[right]; intI, j =0; for(i =0; I < right; i++){ if(Citations[i] >=pivot) {Swap (citations, I, j); J++; }} Swap (citations, J, right); returnJ;}voidQuick_sort (int* Citations,intLeftintRight ) { intpivot_position; if(Left >=Right ) { return; } pivot_position=Partition (citations, left, right); Quick_sort (citations, left, Pivot_position-1); Quick_sort (citations, pivot_position+1, right);}intHindex (int* Citations,intcitationssize) { inti; Quick_sort (citations,0, Citationssize-1); for(i = citationssize-1; I >=0; i--){ if(Citations[i] >= i +1){ returni +1; } } return 0;}
Leetcode OJ 274. H-index