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指数)的更多相关文章

  1. [LeetCode] H-Index II 求H指数之二

    Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize ...

  2. LeetCode OJ 题解

    博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...

  3. [LeetCode OJ] Copy List with Random Pointer 扩大

    职务地址:https://oj.leetcode.com/problems/copy-list-with-random-pointer/ 题意:对一个有回路的链表的深复制 解题:这道题我AC了之后才发 ...

  4. LeetCode OJ 274. H-Index

    Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...

  5. LeetCode OJ学习

    一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...

  6. 【LeetCode OJ】Interleaving String

    Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...

  7. 【LeetCode OJ】Reverse Words in a String

    Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...

  8. 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 ...

  9. 备份LeetCode OJ自己编写的代码

    常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...

随机推荐

  1. 对java NIO 通道的一些了解

    @引言 reactor(反应器)模式 使用单线程模拟多线程,提高资源利用率和程序的效率,增加系统吞吐量.下面例子比较形象的说明了什么是反应器模式: 一个老板经营一个饭店, 传统模式 - 来一个客人安排 ...

  2. 超级强大的vim配置(vimplus)--续集

    An automatic configuration program for vim 安装(github地址:https://github.com/chxuan/vimplus.git, 欢迎star ...

  3. Tomcat的工作模式和运行模式

    (1)工作模式 Tomcat作为servlet容器,有三种工作模式: 1.独立的servlet容器,servlet容器是web服务器的一部分: 2.进程内的servlet容器,servlet容器是作为 ...

  4. jquery的prev选择器无效

    今天使用jquery操作dom 需要把当前元素的同级元素中前面带有属性a=1的元素筛选出来. 查看api, .prev()  获得匹配元素集合中每个元素紧邻的前一个同辈元素,由选择器筛选(可选). 看 ...

  5. WCF服务类的实例模式(本文为转载)

    WCF开发时如何选择正确的实例模式(InstanceMode)?   在使用WCF实例模型时,你是否思考过这几个的问题: ”WCF中的实例模式如何正确应用”? ”使用WCF中的实例模式有何原则可以遵循 ...

  6. nginx结合fastcgi

    1.首先安装nginx,这里采用编译安装 useradd -M -s /sbin/nologin nginx 安装一些依赖包: yum -y install pcre-devel libxslt-de ...

  7. 20145230熊佳炜《逆向及BOF基础实践》

    20145230熊佳炜<逆向及BOF基础实践> 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件.该程序同时包含另一个代码片段,getShell,会返回一个可用Shell. ...

  8. 彻底的卸载干净oracle 11g

    1.关闭oracle所有的服务.可以在windows的服务管理器中关闭:   2.打开注册表:regedit 打开路径: <找注册表 :开始->运行->regedit>   H ...

  9. JS 如何获取当前上一个月、下一个月和月份所含天数

    在数据报表查询中,经常需要设置查询的日期区间,如查询2018-02-01至2018-02-28的整月数据,这时需要提供快捷整月查询按钮: 如: 一般日期年月日之间由"-"或者&qu ...

  10. Python学习札记(一) 初始python

    参考: 廖雪峰教程:Python简介 笔记 1.C语言是可以用来编写操作系统的贴近硬件的语言,所以,C语言适合开发那些追求运行速度.充分发挥硬件性能的程序.而Python是用来编写应用程序的高级编程语 ...