LC 274. H-Index
2024-10-06 23:36:11
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."
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.
Runtime: 4 ms, faster than 72.66% of C++ online submissions for H-Index.
STL的应用。
#define ALL(x) (x).begin(),(x).end()
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
int hIndex(vector<int>& citations) {
sort(ALL(citations));
reverse(ALL(citations));
int idx = citations.size()+;
for(int i=; i<citations.size(); i++){
if(citations[i] < i+) {
idx = i+;
break;
}
}
return idx-;
}
};
最新文章
- html5快速入门(四)—— JavaScript
- CSS3的calc()使用
- 为linux普通用户添加超级用户权限sudo
- Linux学习心得之 jnlp的文件和java应用程序安全设置
- .net串口通信
- Java基础(60):Java打包生成Jar和Javadoc说明文档,以及在另外的工程中导入和使用自己的Jar
- 【每日scrum】NO.1
- 从零开始学android开发-布局中 layout_gravity、gravity、orientation、layout_weight
- Makefile学习与进阶之Makefile.am和$$(M)的意思
- 关于STM32 定时器 PWM 实时调节占空比时,预装载特性
- MySQL数据库触发器(trigger)
- Build MySQL 5.7.4 in RedHat
- POJ2796(单调栈)
- MongoDB原子操作
- Flask中使用Flask-Migrate扩展迁移数据库
- Java实现2048小游戏【代码】
- 学号:201621123032 《Java程序设计》第8周学习总结
- Js JSON.stringify()与JSON.parse()与eval()详解及使用案例
- Spark编译
- Uniform Generator HDU1014
热门文章
- 逆向破解 H.Koenig 遥控器 Part 1
- UNetbootin安装linux
- 使用 jenkins 为 nginx 增加上下文
- Scala(一)——基本类型
- 复习rem
- c++字符和字符串转整数类型及大小端
- LeetCode02 - 两数相加(Java 实现)
- Tampermonkey油猴脚本管理插件-最强浏览器插件的安装使用全攻略
- cookie实例---显示上一次访问的时间与java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie value
- Java-JsonUtil工具类