LeetCode[274] H-Index
2016-09-16 16:49
465 查看
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 least h citations each, and the other N − h papers have no more than h citations
each."
For example, given
in total and each of them had received
researcher has
each and the remaining two with no more than
each, his h-index is
Note: If there are several possible values for
the maximum one is taken as the h-index.
意思是这个人至多有h篇文章被引用了至少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();
}
};
According to the definition of h-index on Wikipedia: "A scientist has index h if h of
his/her N papers have at least h citations each, and the other N − h papers have no more than h citations
each."
For example, given
citations = [3, 0, 6, 1, 5], which means the researcher has
5papers
in total and each of them had received
3, 0, 6, 1, 5citations respectively. Since the
researcher has
3papers with at least
3citations
each and the remaining two with no more than
3citations
each, his h-index is
3.
Note: If there are several possible values for
h,
the maximum one is taken as the h-index.
意思是这个人至多有h篇文章被引用了至少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();
}
};
相关文章推荐
- C++ Vector用法详解
- 详解C++编程中的vector类容器用法
- 详解C++中的vector容器及用迭代器访问vector的方法
- C++实现 vector 的四则运算
- 大家注意vector, list, set, map成员函数erase
- java中vector与hashtable操作实例分享
- C++ vector删除符合条件的元素示例分享
- C++中vector容器的常用操作方法实例总结
- 使用C语言实现vector动态数组的实例分享
- C++ Vector用法深入剖析
- vector与map的erase()函数详细解析
- 深入理解C++中的vector类的用法及特性
- vector,map,list,queue的区别详细解析
- C++ vector的用法小结
- C++中的vector容器对象学习笔记
- stl容器set,map,vector之erase用法与返回值详细解析
- C++中vector的用法实例解析
- c++ vector(向量)使用方法详解(顺序访问vector的多种方式)
- 关于STL中vector容器的一些总结
- JAVA Vector源码解析和示例代码