LeetCode OJ:H-Index(H指数)
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."
For example, given citations = [3, 0, 6, 1, 5]
, which 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, his h-index is 3
.
Note: If there are several possible values for h
, the maximum one is taken as the h-index.
感觉这题更加像动归,没写出来,看了别人的实现,代码如下:
class Solution {
public:
int hIndex(vector<int>& citations) {
int n = citations.size();
vector<int>index(n + , );//注意这里是n+1
for(int i = ; i < n; ++i){
if(citations[i]>=n)
index[n]++;
else
index[citations[i]]++;
}
if(index[n] >= n) return n;
for(int i = citations.size()-; i >= ; --i){
index[i]+=index[i+];
if(index[i] >= i)
return i;
}
return ;
}
};
LeetCode OJ:H-Index(H指数)的更多相关文章
- [LeetCode] H-Index II 求H指数之二
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize ...
- LeetCode OJ 题解
博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...
- [LeetCode OJ] Copy List with Random Pointer 扩大
职务地址:https://oj.leetcode.com/problems/copy-list-with-random-pointer/ 题意:对一个有回路的链表的深复制 解题:这道题我AC了之后才发 ...
- LeetCode OJ 274. H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...
- LeetCode OJ学习
一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...
- 【LeetCode OJ】Interleaving String
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...
- 【LeetCode OJ】Reverse Words in a String
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...
- LeetCode OJ 297. Serialize and Deserialize Binary Tree
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- 备份LeetCode OJ自己编写的代码
常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...
随机推荐
- linux系统中python版本升级
一,查看python版本号 python -V 二,下载需要升级到python版本包下载地址https://www.python.org/ftp/python/ 根据需要选择需要的python版本 e ...
- timestamp类型在jsp页面输出格式化方法
jsp页面使用了iterator迭代器,迭代器中有个属性名字为time,其类型为timestamp类型的,至于为什么是这个类型嘛,就是用navicat建好数据库直接映射出来的实体类,所以就是这个类型啦 ...
- 页面渲染是否结束 与 jquery插件方法是否可以应用
只有页面全部 渲染结束,才可以调用 插件的方法. 正确写法: $(function(){ 插件调用方法. })
- jQuery :gt 选择器 jQuery :lt 选择器
选择前 3 个之后的所有 <tr> 元素: $("tr:gt(2)"); 选择前 2 个 <tr> 元素: $("tr:lt(2)");
- JPA、JTA与JMS
三者都属于Java企业级规范 JPA(java persistence API) JPA 通过JDK5.0的注解或XML来描述 对象-关系表的映射关系,并将运行期的实体对象持久化存储到数据库中. JT ...
- linux下安装mysql详细步骤
最近买了个阿里云服务器,搭建mysql环境. 该笔记用于系统上未装过mysql的干净系统第一次安装mysql.自己指定安装目录,指定数据文件目录. linux系统版本: CentOS 7.3 64位 ...
- mybatis缓存有关的设置和属性
知识点:mybatis缓存相关的设置和属性 重点:每次执行增删改操作后,一二级缓存被清空,是因为标签设置默认属性为 flushCache="true" (1) <!-- 全局 ...
- Linux 服务器buff/cache清理
使用Top命令查看内存及缓冲区使用情况 当磁盘频繁产生IO时会导致buff/cache占用很高的内存,导致可用物理内存很少 但是当真正需要内存时,缓冲区内存会自动释放. 如果需要清理可以用 cache ...
- 初识numpy的多维数组对象ndarray
PS:内容来源于<利用Python进行数据分析> 一.创建ndarray 1.array :将一个序列(嵌套序列)转换为一个数组(多维数组) In[2]: import numpy as ...
- kotlin 记录(已弃坑)
kotlin 有些是转载内容 使用nullable值以及空值检测 引用或函数返回值如果可能为null值,则必须显式标记nullable. (在类型后面跟一个问号表示这个对象可能为空,跟两个感叹号表示这 ...