当前位置:网站首页>H index problem

H index problem

2022-06-22 03:41:00 Yu who wants to fly

H Index

stem :

Given an array of times a researcher's paper is cited ( The number of references is a non negative integer ). Write a method , Calculate the researcher's h Index .

h The definition of index :h representative “ High citations ”(high citations), A researcher's h The index refers to him ( she ) Of (N In a paper ) All in all h At least one of the papers was cited h Time . And the rest N - h Number of citations per paper No more than h Time .

for example : Someone's h The index is 20, This means that in his published papers , Each article is quoted at least 20 There are a total of 20 piece .

Answer key :

class Solution {
    
    public int hIndex(int[] citations) {
    
        int length = citations.length;
        for(int i=length;i>0;i--){
    
            int k=0;
            for(int j = 0;j<length;j++){
    
                if(citations[j]>=i){
    
                    k++;
                }
                if(k>=i){
    
                    return k;
                }
            }
        }
        return 0;
    }
}

Here is a simple and crude method , Direct double layer for Circular application , Outer layer for Cycle from large to small , Once found greater than i The direct return of .

原网站

版权声明
本文为[Yu who wants to fly]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220329265359.html