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 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, her h-index is 3.

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-;
}
};

最新文章

  1. html5快速入门(四)—— JavaScript
  2. CSS3的calc()使用
  3. 为linux普通用户添加超级用户权限sudo
  4. Linux学习心得之 jnlp的文件和java应用程序安全设置
  5. .net串口通信
  6. Java基础(60):Java打包生成Jar和Javadoc说明文档,以及在另外的工程中导入和使用自己的Jar
  7. 【每日scrum】NO.1
  8. 从零开始学android开发-布局中 layout_gravity、gravity、orientation、layout_weight
  9. Makefile学习与进阶之Makefile.am和$$(M)的意思
  10. 关于STM32 定时器 PWM 实时调节占空比时,预装载特性
  11. MySQL数据库触发器(trigger)
  12. Build MySQL 5.7.4 in RedHat
  13. POJ2796(单调栈)
  14. MongoDB原子操作
  15. Flask中使用Flask-Migrate扩展迁移数据库
  16. Java实现2048小游戏【代码】
  17. 学号:201621123032 《Java程序设计》第8周学习总结
  18. Js JSON.stringify()与JSON.parse()与eval()详解及使用案例
  19. Spark编译
  20. Uniform Generator HDU1014

热门文章

  1. 逆向破解 H.Koenig 遥控器 Part 1
  2. UNetbootin安装linux
  3. 使用 jenkins 为 nginx 增加上下文
  4. Scala(一)——基本类型
  5. 复习rem
  6. c++字符和字符串转整数类型及大小端
  7. LeetCode02 - 两数相加(Java 实现)
  8. Tampermonkey油猴脚本管理插件-最强浏览器插件的安装使用全攻略
  9. cookie实例---显示上一次访问的时间与java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie value
  10. Java-JsonUtil工具类