给你一个整数数组 citations
,其中 citations[i]
表示研究者的第 i
篇论文被引用的次数。计算并返回该研究者的 h
指数。
根据维基百科上 h 指数的定义:h
代表“高引用次数” ,一名科研人员的 h
指数 是指他(她)至少发表了 h
篇论文,并且 至少 有 h
篇论文被引用次数大于等于 h
。如果 h
有多种可能的值,h
指数 是其中最大的那个。
话不多说先上代码
class Solution {
public:
int hIndex(vector<int>& citations) {
sort(citations.begin(),citations.end());
int cnt = 0;
int i = citations.size() - 1;
while (i >= 0 && citations[i] > cnt) {
cnt++;
i--;
}
return cnt;
}
};
//0 1 3 5 6
对于这个题目我第一时间想的就是想给他排序,因为先从小的开始H指数来一步一步寻找,然后对于引用次数的大小来判断是否要加H指数,如果找到了一个至少H+1次的论文,我们就把原来的H指数加1