Leetcode274.H-IndexH指数
原题的中文翻译不是很好,所以给出英文版。
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.
我的理解:
h指数就是在总N篇文章中有h篇文章中引用次数至少为h。
剩下的N-h篇文章的引用次数不超过h。
找最大的h,最大的h为N,所以从h = N开始遍历验证。
class Solution {
public:
int hIndex(vector<int>& citations)
{
sort(citations.begin(), citations.end());
int ans = citations.size();
for (int i = 0; i < citations.size(); i++)
{
if (ans <= citations[i])
{
break;
}
//文章数-1, h指数-1
else
{
ans--;
}
}
return ans;
}
};
Leetcode274.H-IndexH指数的更多相关文章
- 指数基金介绍专栏(8):国企指数(H股指数)详细介绍,最新资料解析,看这一篇就够了
作者:牛大 | 公众号:定投五分钟 大家好,我是牛大.每天五分钟,投资你自己:坚持基金定投,终会财富自由! 昨天牛大给大家介绍了恒生指数,没看的朋友可以去公众号看一下. 指数基金介绍专栏(7):恒生指 ...
- [Swift]LeetCode274.H指数 | H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...
- 51nod1986 Jason曾不想做的数论题
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1986 方便起见,公式中的区间内只考虑整数,X的gcd,lcm定义为每个元 ...
- Codeforces 799D Field expansion - 搜索 - 贪心
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game p ...
- 遗传编程(GA,genetic programming)算法初探,以及用遗传编程自动生成符合题解的正则表达式的实践
1. 遗传编程简介 0x1:什么是遗传编程算法,和传统机器学习算法有什么区别 传统上,我们接触的机器学习算法,都是被设计为解决某一个某一类问题的确定性算法.对于这些机器学习算法来说,唯一的灵活性体现在 ...
- [LeetCode] H-Index 求H指数
Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...
- [Swift]LeetCode275. H指数 II | H-Index II
Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a ...
- H指数
H指数是用来综合衡量学者发表论文的数量和质量的指标,若某学者共发表N篇论文,H指数是指存在h 篇论文至少每篇有h 引用量,剩下的N-h篇中,每篇都不超过h引用量 计算H指数的方法:1.排序法思路:先将 ...
- 为什么Java的hash表的长度一直是2的指数次幂?为什么这个(hash&(h-1)=hash%h)位运算公式等价于取余运算?
1.什么是hash表? 答:简单回答散列表,在hash结构散列(分散)存放的一种数据集结构. 2.如何散列排布,如何均匀排布? 答:取余运算 3.Java中如何实现? 答:hash&(h-1) ...
- Leetcode 274.H指数
H指数 给定一位研究者论文被引用次数的数组(被引用次数是非负整数).编写一个方法,计算出研究者的 h 指数. h 指数的定义: "一位有 h 指数的学者,代表他(她)的 N 篇论文中至多有 ...
随机推荐
- MySQL数据库(五)—— 用户管理、pymysql模块
用户权限管理.pymysql模块 一.用户管理(权限管理) 在MySQL中自带的mysql数据库中有4个表用于用户管理的 # 优先级从高到低 user > db > tables_priv ...
- jQuery实用美化input 上传组建
下载插件 (5) 简要教程 jquery-filestyle是一款可以简单实用的表单文件上传域美化jQuery插件.该插件可以将表单的文件上传域转换为类似Bootstrap按钮组的样式 ...
- ajax图片上传
使用ajaxfileupload.js插件 html代码: <p> <label>ajax上传</label> <input type="file& ...
- CDH5..4.7+phoenix实现查询HBase异常:java.sql.SQLException: ERROR 1102 (XCL02): Cannot get all table regions
基础环境是用CM 安装的cdh5.4.7,phoenix使用的版本是phoenix-4.5.2-HBase-1.0-bin. 出现异常信息:java.sql.SQLException: ERROR 1 ...
- Ansible随笔8
自定义模块的开发模式 1.决定自定义模块的存放路径 编辑/etc/ansible/ansible.cfg文件,修改library = /usr/share/ansible/. 这样就告诉ansible ...
- 富文本编辑器 CKeditor 配置使用+上传图片
参考文献: 富文本编辑器 CKeditor 配置使用 CKEditor与CKFinder的配置(ASP.NET环境),老版本可以参考 CKEditor+CKFinder ASP版在本地电脑中的配置 ...
- Linux 进程间通信 消息队列 实现两个进程间通信
例子: 通过消息队列实现两个进程间通信,一个进程从终端输入数据,通过消息队列发送,另一个进程通过消息队列接收数据 文件1 创建进程1 终端输入通过消息队列发送数据 #include <stdio ...
- Python 刷题知识点
if : elif : else : print('{0} \n{1} \n{2}' .format((a + b), (a - b), (a * b))) print(*[num**2 for nu ...
- 删除重复数据并保留id最小的一条记录
delete from test where id not in ( select a.id from (select min(id) as id from test group by form_i ...
- delphi 文件存取方法与文件管理组件
9.2 文件存取方法与文件管理组件 9.2.1 存取文件的类方法 Delphi在许多需要与文件打交道的类中定义了文件存取方法,使用这些方法可以非常方便地将类中的数据保存到文件中,或从文件中读取所需 ...