[LeetCode] H-Index 求H指数
LeetCode index 指数
2023-09-11 14:21:39 时间
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 leasth citations each, and the other N − h papers have no more than h citations each."
Example:
Input:citations = [3,0,6,1,5]
Output: 3 Explanation:[3,0,6,1,5]
means the researcher has5
papers in total and each of them had received3, 0, 6, 1, 5
citations respectively. Since the researcher has3
papers with at least3
citations each and the remaining two with no more than3
citations each, her h-index is3
.
Note: If there are several possible values for h, the maximum one is taken as the h-index.
这道题让我们求H指数,这个质数是用来衡量研究人员的学术水平的质数,定义为一个人的学术文章有n篇分别被引用了n次,那么H指数就是n。而且wiki上直接给出了算法,可以按照如下方法确定某人的H指数:1、将其发表的所有SCI论文按被引次数从高到低排序;2、从前往后查找排序后的列表,直到某篇论文的序号大于该论文被引次数。所得序号减一即为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(); } };
类似题目:
参考资料:
https://leetcode.com/problems/h-index/
相关文章
- Java实现 LeetCode 740 删除与获得点数(递推 || 动态规划?打家劫舍Ⅳ)
- Java实现 LeetCode 722 删除注释(暴力筛选)
- Java实现 LeetCode 664 奇怪的打印机(DFS)
- Java实现 LeetCode 405 数字转换为十六进制数
- Java实现 LeetCode 394 字符串解码
- Java实现 LeetCode 300 最长上升子序列
- Java实现 LeetCode 268 缺失数字
- Java实现 LeetCode 124 二叉树中的最大路径和
- Java实现 LeetCode 33 搜索旋转排序数组
- 【LeetCode算法-9】Palindrome Number
- LeetCode(80):删除排序数组中的重复项 II
- LeetCode - 46 全排列
- LeetCode:Find Minimum in Rotated Sorted Array
- leetcode 724. Find Pivot Index
- leetcode 599. Minimum Index Sum of Two Lists
- 【Leetcode刷题Python】 LeetCode 2038. 如果相邻两个颜色均相同则删除当前颜色