275. H-index II

Source: Internet
Author: User

            }     /** 275. H-index II * 1.3 by Mingyang * Input array with linear solution in sort is ordered, let's do the calculation in O (log n) time, * We first initialize left and right for 0 and array Length len-1, then take the median mid, * compare Citations[mid] and len-mid to compare, if the former is large, then right before moving to mid, * the reverse is after moving to mid, the terminating condition is left>right, and the last return Le N-left * for Paper[m]. There should is at least (len–m) papers with citations >= Citations[m]*/      Public Static intHindex (int[] citations) {            if(Citations = =NULL|| Citations.length = = 0) {                return0; }                         intLow = 0; intHigh = Citations.length-1; intLen =citations.length;  while(Low <=High ) {                intMid = (low + high)/2; if(Citations[mid] = = Len-mid)returnLen-mid;//The number of K is equal to K, and the----len-mid indicates that the number is from the big to the small row in the first few                Else if(Citations[mid] > Len-mid) high = Mid-1; ElseLow = mid + 1; }            returnLen-Low ; }     //Methods of Meng      Public intHIndex2 (int[] citations) {            intlen=citations.length; if(len==0)             return0; intLeft=0,right=len-1;  while(left<=Right ) {                intmid=left+ (right-left)/2; //0 4 5 6 7 5>=3//4>=4                if(Citations[mid]>=len-mid)//--------mid=2                {                    if(mid==0| | Citations[mid-1]<len-mid+1)                        returnlen-mid; Else Right=mid-1;//0 4//                }                Else Left=mid+1; }            return0; }

275. H-index II

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.