} /** 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