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. 带你走进AJAX(1)

    ajax是什么? (1)ajax (asynchronouse javascript and xml) 异步的javascript 和xml (2)ajax是一个粘合剂,将javascript.xml ...

  2. linux命令——chmod/chown

    改变文件所有权chown 例如 sudo chown username myfile 1 myfile文件的所有权变为username. chown -R username /files/work 1 ...

  3. Myeclipse中java项目转换为Web项目

    https://blog.csdn.net/u010097777/article/details/51281059 这两天工作安排做一个跳转页面,不过昨天发布自己的Tomact花了不少时间,给的项目添 ...

  4. 1_archlinux_安装篇

    系统安装 可参考网友的文章: https://www.douban.com/note/263375303/?type=like http://www.68idc.cn/help/server/linu ...

  5. Painter's Problem

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5378   Accepted: 2601 Description There ...

  6. linux下tar的使用方法

    1.仅打包 tar -cvf hello.tar hello (输出文件大小为10240) 2.打包后压缩成gzip压缩格式 tar -czvf hello.tar.gz hello (输出文件大小为 ...

  7. mySQL 多表查询语句

    多表查询最少有2张以上的表一起查询 交叉连接查询(很少用)查询出来的数据是错误的 内连接 [inner] join on 隐式省略inner join on select  from 表A,表B wh ...

  8. Azure Active Directory配置java应用的单点登录

    下载应用:https://github.com/Azure-Samples/active-directory-java-webapp-openidconnect(普通项目,集成了特殊配置接入微软的注册 ...

  9. LeetCode——Unique Paths

    Question A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram be ...

  10. raid1磁盘更换---测试

    安装centos6.71. CentOS安装过程配raid.参考:http://www.360doc.com/content/13/1209/21/14661619_335823338.shtml. ...