[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.html

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:post

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

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

 

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

 

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();
    }
};

 

相似題目:code

H-Index IIhtm

 

參考資料:blog

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

 

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

相關文章
相關標籤/搜索