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

LC 274. H-Index的更多相关文章

  1. Java实现 LeetCode 274 H指数

    274. H指数 给定一位研究者论文被引用次数的数组(被引用次数是非负整数).编写一个方法,计算出研究者的 h 指数. h 指数的定义: "h 代表"高引用次数"(hig ...

  2. Leetcode 274.H指数

    H指数 给定一位研究者论文被引用次数的数组(被引用次数是非负整数).编写一个方法,计算出研究者的 h 指数. h 指数的定义: "一位有 h 指数的学者,代表他(她)的 N 篇论文中至多有 ...

  3. LC 599. Minimum Index Sum of Two Lists

    题目描述 Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of fav ...

  4. HDU-6278-Jsut$h$-index(主席树)

    链接: https://vjudge.net/problem/HDU-6278 题意: The h-index of an author is the largest h where he has a ...

  5. [LeetCode] 274. H-Index H指数

    Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...

  6. jQuery—一些常见方法(1)【filter(),not(),has(),next(),prev(),find(),eq(),index(),attr(),】

    1.filter()和not()方法 filter()和not()是一对反方法,filter()是过滤. filter()方法是针对元素自身.(跟has()方法有区别) <script type ...

  7. FFmpeg的H.264解码器源代码简单分析:熵解码(Entropy Decoding)部分

    ===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...

  8. LeetCode(274)H-Index

    题目 Given an array of citations (each citation is a non-negative integer) of a researcher, write a fu ...

  9. 自学JQuery Mobile的几个例子

    JQuery Mobile是一个用于构建移动Web应用程序的框架,适用于主流的移动设备(智能手机.平板电脑),该框架利用了HTML5和CSS3技术减少了额外的脚本文件的编写.具体JQuery Mobi ...

随机推荐

  1. 【0】Zookeeper Q&A

    1.Observer角色如何配置? Zookeeper集群中的中的Leader和Follower角色是由服务器启动时期的Leader选举产生的,Observer不参与选举,此角色的节点需要在配置文件z ...

  2. odoo标识符

    class Book(models.Model): _name = "library.book" _description = "Book" _order = ...

  3. 【异常】Could not find artifact com.wm.****:

    1 详细异常 [ERROR] Failed to execute goal on project spark-etl: Could not resolve dependencies for proje ...

  4. PhotoShop更改图片背景色

    PhotoShop更改图片背景色 操作步骤如下所示: 打开图片==>图像/调整/替换颜色==>选择颜色==>选择油漆桶工具==>点击需要被替换的图片背景色 注:不知道什么原因 ...

  5. 八,kubernetes集群存储卷基础。

    目录 存储卷 存储的分类 emptyDir 测试及使用 hostpath实例 Pod测试挂在共享NFS 写测试清单 测试 pv, pvc 创建几个PV 创建测试的Pod 和 PVC 存储卷 pod运行 ...

  6. uvalive 5905 Pool construction

    题目链接 题意: 有一个花园,有些地方是草地,有些地方是洞,现在要在这个花园中修建一个泳池,泳池全部由洞构成. 把洞变成草地需要花费一定的费用,把草地变成洞也需要花费一定的费用,并且泳池的边缘的草地上 ...

  7. static和assets的区别

    assets和static两个都是用于存放静态资源文件. 放在static中的文件不会进行构建编译处理,也就不会压缩体积,在打包时效率会更高,但体积更大在服务器中就会占据更大的空间 放在assets中 ...

  8. 移动端H5不常见兼容收集

    1.微信分身input不支持上传,无法监听到上传事件 解决方案:判断在微信浏览器端使用微信JSSDK上传

  9. 万能正则解析 json 数据 解析成键值对

    string txt = "{\"ip\": \"127.0.0.1\", \"port\": 80, \"status ...

  10. confirm 弹出信息

    if(confirm("真的要删除吗?")){ alert("点击了确认按钮"); } else{ alert("点击了取消按钮"); } ...