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 ...
随机推荐
- 记录旧手机(米6)安装Linux(Ubuntu16.04)踩过的坑
旧的小米6在抽屉吃灰半年,一直没想好要怎么处理,于是就想着安装Linux. 完整教程来自https://blog.csdn.net/Greepex/article/details/85333027 原 ...
- 9月24日开始发布,主打安全的Librem 5 Linux手机
曾推出搭载PureOS Linux发行版本Librem笔记本系列的硬件厂商Purism,今天正式宣布了Librem 5 Linux手机的最终和官方发售日期.Librem 5于2017年10月正式发布, ...
- FASTCGI/CGI
在了解这两个协议之前,我们先谈一下动态网页 动态网页 是指跟静态网页相对的一种网页编程技术.静态网页,随着html代码的生成,页面的内容和显示效果就基本上不会发生变化了--除非你修改页面代码.而动态网 ...
- LeetCode NO477.汉明距离总和
两个整数的 汉明距离 指的是这两个数字的二进制数对应位不同的数量. 计算一个数组中,任意两个数之间汉明距离的总和. 示例: 输入: 4, 14, 2 输出: 6 解释: 在二进制表示中,4表示为010 ...
- zabbix 3.2.2 agent端(源码包)安装部署 (二)
一.zabbix agent 端安装部署 1.创建zabbix用户和组 # groupadd zabbix # useradd -g zabbix zabbix -s /sbin/nologin 2. ...
- 9.RNN应用
import numpy as np from keras.datasets import mnist from keras.utils import np_utils from keras.mode ...
- python学习笔记-(十三)线程、进程、多线程&多进程
为了方便大家理解下面的知识,可以先看一篇文章:http://www.ruanyifeng.com/blog/2013/04/processes_and_threads.html 线程 1.什么是线程? ...
- cypress 3
https://blog.csdn.net/u014647208/article/details/80525226 https://blog.csdn.net/kulala082/article/de ...
- 不能使用 float 和 double 来表示金额等精确的值
不能使用 float 和 double 来表示金额等精确的值 关于面试,金额用什么数据类型? 不是 doube,更不是 float ,而是用 BigDecimal.对于金融项目,对于金额,误差是不能容 ...
- LeetCode02 - 两数相加(Java 实现)
LeetCode02 - 两数相加(Java 实现) 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/add-two-numbers 题目描述 ...