Leetcode OJ 274. H-index

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.