LeetCode 274 H-Index (H索引)

简介: 版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/51753099 翻译给定一个研究者的引用数(每个引用都是非负数)的数组,写一个函数用于计算研究者的h索引。
版权声明:转载请联系本人,感谢配合!本站地址:http://blog.csdn.net/nomasp https://blog.csdn.net/NoMasp/article/details/51753099

翻译

给定一个研究者的引用数(每个引用都是非负数)的数组,写一个函数用于计算研究者的h索引。

根据维基百科对于h-index的定义:“一个科学家有索引h,如果他或他的N篇论文至少存在h个相互引用,而且其他的N-h篇论文相互引用次数不高于h。

例如,给定citations = [3, 0, 6, 1, 5],这意味着研究者总共有5篇论文,而且每一篇论文分别收到3、0、6、1、5次相互引用。

因为研究者有3篇论文存在至少3次引用(译者注:即数组的第0、2、4篇论文分别存在3、6、5次引用),而其余剩下的则不超过3次相互引用,所以他的h-index是3。

备注:如果对于h有多个可能的值,那么取最大值作为h-index。

原文

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 citations = [3, 0, 6, 1, 5], which 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, his h-index is 3.

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

代码

这道题只要在草稿纸上,推理一下,很容易就可以写出代码,就不多说了。

class Solution {
public:
int hIndex(vector<int>& citations) {
    sort(citations.begin(), citations.end(), greater<int>());
    int h = 0;
    for (int i = 0; i < citations.size(); i++) {
        if (i < citations[i]) {
            h++;
        }
    }
    return h;
}
};
目录
相关文章
|
2月前
|
算法 Java 索引
LeetCode初级算法题:寻找数组的中心索引+x的平方根+三个数的最大乘积+Leetcode 149:直线上最多的点数 Java详解
LeetCode初级算法题:寻找数组的中心索引+x的平方根+三个数的最大乘积+Leetcode 149:直线上最多的点数 Java详解
30 0
|
2月前
|
算法 索引 Python
【Leetcode刷题Python】852. 山脉数组的峰顶索引
本文使用二分查找算法解决LeetCode "山脉数组的峰顶索引" 问题的Python实现,通过递归地缩小搜索区间来查找山脉数组的峰值索引。
20 0
|
4月前
|
索引
【LeetCode刷题】二分查找:山脉数组的峰顶索引、寻找峰值
【LeetCode刷题】二分查找:山脉数组的峰顶索引、寻找峰值
|
4月前
|
算法 数据挖掘 开发者
LeetCode题目55:跳跃游戏【python5种算法贪心/回溯/动态规划/优化贪心/索引哈希映射 详解】
LeetCode题目55:跳跃游戏【python5种算法贪心/回溯/动态规划/优化贪心/索引哈希映射 详解】
|
5月前
|
索引
Leetcode 给定一个数组,给定一个数字。返回数组中可以相加得到指定数字的两个索引
Leetcode 给定一个数组,给定一个数字。返回数组中可以相加得到指定数字的两个索引
|
12月前
|
人工智能 BI 索引
【Leetcode -598.范围求和Ⅱ -599.两个列表的最小索引总和】
【Leetcode -598.范围求和Ⅱ -599.两个列表的最小索引总和】
37 0
|
5月前
|
开发者 索引 Python
【python刷题】LeetCode 2057E 值相等的最小索引(5种简单高效的解法)
【python刷题】LeetCode 2057E 值相等的最小索引(5种简单高效的解法)
44 0
|
索引
LeetCode每日一题(9)——随机数索引(理解水塘抽样)
随机数索引 1.题目 2.示例 3.思路及代码
122 0
LeetCode每日一题(9)——随机数索引(理解水塘抽样)
|
索引 Python
LeetCode 599. 两个列表的最小索引总和
假设Andy和Doris想在晚餐时选择一家餐厅,并且他们都有一个表示最喜爱餐厅的列表,每个餐厅的名字用字符串表示。
90 0