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. servlet遇到的问题

    1 创建web项目没有xml自动生成 2  servlet 忽然报奇怪500错误  出现的BUG原因 JAVA bean没有设置  自动导入了其他User包

  2. 移动端的文本框获取焦点时导致fixed或absolute定位的按钮被手机键盘顶上去的问题

    var win_h = $(window).height();//关键代码 window.addEventListener('resize', function () { if($(window).h ...

  3. tensorflow2.0 在pycharm下提示问题

    tensorflow2.0 使用keras一般通过tensorflow.keras来使用,但是pycharm没有提示,原因是因为实际的keras路径放在tensorflow/python/keras, ...

  4. 使用Quartus进行功能仿真时出现“testbench_vector_input_file option does not exist”的解决方法

    环境:本人使用的Quartus 18 Prime Standard Edition 1.新建一个vmf文件 ​ 添加Node或者Bus ​ 2.点击Processing->Start->S ...

  5. python--AutoPy库

    包括用于控制键盘和鼠标,在屏幕上查找颜色和位图以及显示警报的功能 - 所有这些都是以跨平台,高效和简单的方式进行的.适用于Mac OS X,Windows和X11 中文文档:https://blog. ...

  6. C# 数组转字符串显示

    , , , , , , , }; arry[] = (] | ); string result = String.Join("", arry); Console.WriteLine ...

  7. DOM 事件流与事件处理程序

    ㈠事件流 ▶事件:是文档和浏览器窗口中发生的,特定的交互瞬间. ▶事件流:描述的是从页面中接受事件的顺序   ⑴DOM事件冒泡 定义:事件最开始由最具体的元素(文档中嵌套层次最深的那个节点)接受,然后 ...

  8. call和ret指令

    call和ret都是用来修改ip或cs:ip,可以用来实现子程序的设计:   1.ret和retf ret    ->修改ip的内容,从而实现近转移: retf    ->同时修改cs和i ...

  9. 「SNOI2017」礼物

    题目链接:Click here Solution: 设\(f(x)\)代表第\(x\)个人送的礼物的数量,\(s(x)\)代表\(f(x)\)的前缀和,即: \[ f(x)=s(x-1)+x^k\\ ...

  10. 常用C库函数小结

    1. sprintf 原型:int sprintf( char *buffer, const char *format, [ argument] - ); 功能:将格式化后的字符串写在buffer中, ...