/** 274. H-index * 1.2 by Mingyang * The array is sorted first, so we can know how many references to a reference count are greater than this number. For reference number Citations[i], * greater than the number of citations is citations.length-i, * and the current h-index is Math.min (Citations[i], citations.length-i) , * We compare this current H index with the global Maximum H index to get the maximum H exponent. */ Public intHindex (int[] citations) { //SortArrays.sort (citations); intH = 0; for(inti = 0; i < citations.length; i++){ //get the current H index intCurrh = Math.min (Citations[i], citations.length-i); if(Currh >h) {h=Currh; } } returnh; } /** You can also not sort the array, we use an extra size of n+1 array stats. *stats[i] Indicates how many articles have been quoted I times, * here if an article reference is greater than n times, we will use it as n times, * because the H index does not exceed the total number of articles. In order to construct this array, we need to iterate over the entire reference array and add one to the corresponding lattice. * After the statistics, we begin to traverse this statistic array from N to 1. * If you traverse to a certain number of references, the number of articles that are greater than or equal to the number of references, * is greater than the number of references itself, we can think of this as the H index. There is no need to look down, * because we have to take the maximum H index. How do you find the number of articles that are greater than or equal to a certain number of citations? * We can use a variable to accumulate from the number of articles with high citations. Because we know that if there are references to x articles that are greater than or equal to 3 times, the number of articles that reference greater than or equal to 2 times must be X plus the number of citations equals 2 times. */ Public intHIndex2 (int[] citations) { int[] Stats =New int[Citations.length + 1]; intn =citations.length; //count the number of citations that correspond to how many articles for(inti = 0; I < n; i++) {Stats[citations[i]<= n? Citations[i]: n] + = 1; } intsum = 0; //find the maximum H index for(inti = n; i > 0; i--){ //reference the number of articles greater than or equal to I, equal to the number of articles that are greater than or equal to i+1 times, plus the number of articles that reference equals I timesSum + =Stats[i]; //If a reference is greater than or equal to I, the number of articles is greater than the quoted number I, indicating that the H exponent if(Sum >=i) { returni; } } return0; }
274. H-index