LC 274. H-Index
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 has5papers in total and each of them had
received3, 0, 6, 1, 5citations respectively.
Since the researcher has3papers with at least3citations each and the remaining
two with no more than3citations 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-;
}
};
LC 274. H-Index的更多相关文章
- Java实现 LeetCode 274 H指数
274. H指数 给定一位研究者论文被引用次数的数组(被引用次数是非负整数).编写一个方法,计算出研究者的 h 指数. h 指数的定义: "h 代表"高引用次数"(hig ...
- Leetcode 274.H指数
H指数 给定一位研究者论文被引用次数的数组(被引用次数是非负整数).编写一个方法,计算出研究者的 h 指数. h 指数的定义: "一位有 h 指数的学者,代表他(她)的 N 篇论文中至多有 ...
- 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 ...
- 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 ...
- [LeetCode] 274. H-Index H指数
Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...
- jQuery—一些常见方法(1)【filter(),not(),has(),next(),prev(),find(),eq(),index(),attr(),】
1.filter()和not()方法 filter()和not()是一对反方法,filter()是过滤. filter()方法是针对元素自身.(跟has()方法有区别) <script type ...
- FFmpeg的H.264解码器源代码简单分析:熵解码(Entropy Decoding)部分
===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...
- LeetCode(274)H-Index
题目 Given an array of citations (each citation is a non-negative integer) of a researcher, write a fu ...
- 自学JQuery Mobile的几个例子
JQuery Mobile是一个用于构建移动Web应用程序的框架,适用于主流的移动设备(智能手机.平板电脑),该框架利用了HTML5和CSS3技术减少了额外的脚本文件的编写.具体JQuery Mobi ...
随机推荐
- Bmake
Bmake is a common makefile framework. Both support native build and cross build. Easy for use, modif ...
- 第八章· Redis API 开发
Redis 开发 1.源码安装Python环境 Python官网:https://www.python.org/ #下载Python3.6.4安装包 [root@db03 ~]# wget https ...
- 通过WSL使用rsync同步本文件
1.安装WLS 主要参考Windows10上使用Linux子系统(WSL)这篇文章进行安装,不要通过lxrun /install /y去安装,这种方法安装貌似没有wsl命令. 先把win 10 版本升 ...
- idea中添加mybatis mapper 样例
代码: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC &quo ...
- IE8"HTML Parsing Error:Unable to modify the parent container element before the child element is closed"错误
一.IE8报下面错误,解决办法:网页错误详细信息消息: HTML Parsing Error: Unable to modify the parent container element before ...
- BZOJ 世界树
第一步首先建虚树 第二步两遍dfs,一次从叶子到根,一次从根到叶子,就可以得到虚树中每个节点在M个询问点中离他最近的是哪个(简称为控制点) 第三步考虑计算答案,对于整个树,我们把节点化为三个种类 1. ...
- python+Appium自动化:Appium-desktop界面简介
Appium Desktop是一款适用于Mac,Windows和Linux的开源应用程序,提供了更加优化的图形界面. Appium Desktop是由Simple.Advanced.Presets三个 ...
- Storm实践(一):基础知识
storm简介 Storm是一个分布式实时流式计算平台,支持水平扩展,通过追加机器就能提供并发数进而提高处理能力:同时具备自动容错机制,能自动处理进程.机器.网络等异常. 它可以很方便地对流式数据进行 ...
- tcpip入门的网络教程汇总
网络编程懒人入门(一):快速理解网络通信协议(上篇) http://www.52im.net/thread-1095-1-1.html TCP/IP详解学习笔记 https://www.cnblogs ...
- Acwing-168-生日蛋糕(搜索, 剪枝)
链接: https://www.acwing.com/problem/content/170/ 题意: 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆 ...