274. H-Index
2016-06-27 16:22
351 查看
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
has
with at least
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.
Hint:
An easy approach is to sort the array first.
What are the possible values of h-index?
A faster approach is to use extra space.
题意:计算H索引。
思路:直接按定义计算。
class Solution {
public:
int hIndex(vector<int>& citations) {
sort(citations.begin(), citations.end());
const int size = citations.size();
int res=0;
for (int i = 0; i < citations.size(); i++){
if (citations[i] >= size - i){
res = size-i;
break;
}
}
return res;
}
};
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.
Hint:
An easy approach is to sort the array first.
What are the possible values of h-index?
A faster approach is to use extra space.
题意:计算H索引。
思路:直接按定义计算。
class Solution {
public:
int hIndex(vector<int>& citations) {
sort(citations.begin(), citations.end());
const int size = citations.size();
int res=0;
for (int i = 0; i < citations.size(); i++){
if (citations[i] >= size - i){
res = size-i;
break;
}
}
return res;
}
};
相关文章推荐
- 安卓线程池ThreadPoolExecutor的常见使用
- 如何提高大型工程的编译速度?
- permission 和 user-permission的区别
- win8系统蓝屏提示DRIVER POWER STATE FAILURE的原因及两种解决方法
- 欢迎使用CSDN-markdown编辑器
- 使用Popen运行程序超时就kill
- 固定电话的正则表达式
- 修改ubuntu的apt-get软件源(ubuntu的网络问题)
- Yii2 rules验证规则
- 6.27 考试总结
- thinkphp 3.2与phpexcel
- git配置用户名和邮箱
- 001-整数快速幂-归纳法-《算法设计技巧与分析》M.H.A学习笔记
- Interleaving String
- 各国语言对应翻译表
- Consul入门06 - 键/值对数据
- centos系统,基于nginx服务器,用https访问php页面总弹出下载页面问题完美解决
- 终端统计Xcode中项目总共行数
- HDOJ 1812 Count the Tetris
- POJ1273 Drainage Ditches 【最大流】