[LeetCode] H-Index 求H指數


 

Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.

According to the definition of h-index on Wikipedia: "A scientist has index h if h of his/her N papers have at leasth citations each, and the other N − h papers have no more than h citations each."

Example:

Input: citations = [3,0,6,1,5]
Output: 3 
Explanation: [3,0,6,1,5] means the researcher has 5 papers in total and each of them had 
             received 3, 0, 6, 1, 5 citations respectively. 
             Since the researcher has 3 papers with at least 3 citations each and the remaining 
             two with no more than 3 citations each, her h-index is 3.

Note: If there are several possible values for h, the maximum one is taken as the h-index.

 

這道題讓我們求H指數,這個質數是用來衡量研究人員的學術水平的質數,定義為一個人的學術文章有n篇分別被引用了n次,那么H指數就是n。而且wiki上直接給出了算法,可以按照如下方法確定某人的H指數:1、將其發表的所有SCI論文按被引次數從高到低排序;2、從前往后查找排序后的列表,直到某篇論文的序號大於該論文被引次數。所得序號減一即為H指數。我也就沒多想,直接按照上面的方法寫出了代碼:

 

class Solution {
public:
    int hIndex(vector<int>& citations) {
        sort(citations.begin(), citations.end(), greater<int>());
        for (int i = 0; i < citations.size(); ++i) {
            if (i >= citations[i]) return i;
        }
        return citations.size();
    }
};

 

類似題目:

H-Index II

 

參考資料:

https://leetcode.com/problems/h-index/

 

LeetCode All in One 題目講解匯總(持續更新中...)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM