H-Index I

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.

分析:

先排序,然后看倒数第n个的paper它的citation是否超过n.

 public class Solution {
public int hIndex(int[] citations) {
// 排序
Arrays.sort(citations);
int h = ;
for(int i = ; i <= citations.length; i++){
// 最后i个paper的最小index是否大于i
if (citations[citations.length - i] >= i) {
h = Math.max(h, i);
}
}
return h;
}
}

H-Index II

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

 public class Solution {
public int hIndex(int[] citations) {
int start = ;
int end = citations.length - ; while (start <= end) {
int mid = (start + end) / ;
if (citations[mid] >= citations.length - mid) {
end = mid - ;
} else {
start = mid + ;
}
}
return citations.length - start;
}
}

H-Index I & II的更多相关文章

  1. Permutation Index I & II

    Given a permutation which contains no repeated number, find its index in all the permutations of the ...

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

  3. FFmpeg的H.264解码器源代码简单分析:熵解码(Entropy Decoding)部分

    ===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...

  4. [LeetCode] 274. H-Index H指数

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

  5. jQuery—一些常见方法(1)【filter(),not(),has(),next(),prev(),find(),eq(),index(),attr(),】

    1.filter()和not()方法 filter()和not()是一对反方法,filter()是过滤. filter()方法是针对元素自身.(跟has()方法有区别) <script type ...

  6. 浅谈命令查询职责分离(CQRS)模式

    在常用的三层架构中,通常都是通过数据访问层来修改或者查询数据,一般修改和查询使用的是相同的实体.在一些业务逻辑简单的系统中可能没有什么问题,但是随着系统逻辑变得复杂,用户增多,这种设计就会出现一些性能 ...

  7. 【机器学习Machine Learning】资料大全

    昨天总结了深度学习的资料,今天把机器学习的资料也总结一下(友情提示:有些网站需要"科学上网"^_^) 推荐几本好书: 1.Pattern Recognition and Machi ...

  8. 把《c++ primer》读薄(4-2 c和c++的数组 和 指针初探)

    督促读书,总结精华,提炼笔记,抛砖引玉,有不合适的地方,欢迎留言指正. 问题1.我们知道,将一个数组赋给另一个数组,就是将一个数组的元素逐个赋值给另一数组的对应元素,相应的,将一个vector 赋给另 ...

  9. AP(affinity propagation)研究

    待补充…… AP算法,即Affinity propagation,是Brendan J. Frey* 和Delbert Dueck于2007年在science上提出的一种算法(文章链接,维基百科) 现 ...

  10. 机器学习(Machine Learning)&深度学习(Deep Learning)资料【转】

    转自:机器学习(Machine Learning)&深度学习(Deep Learning)资料 <Brief History of Machine Learning> 介绍:这是一 ...

随机推荐

  1. Ubuntu用作Server时出现乱码的解决方法

    下面给出解决办法: 1.用vi编辑器修改/etc/default/local文件 2.把原来的中文编码替换成下面的 LANG="en_US.UTF-8" LANGUAGE=&quo ...

  2. yum管理

    一.yum发展与作用     在linux系统维护中管理员经常遇到软件包的依赖问题,有时无法解决,比如你在安装库文件时常出现报错问题,说依赖其它软件包.由于这个问题一直困绕linux的广大爱好者,开源 ...

  3. Python-面向对象编程(二)

    面向对象进阶篇: 初级篇中我们介绍了面向对象基本知识: 1.面向对象是一种编程方式,此编程方式的实现是基于对 类 和 对象 的使用 2.介绍了类中的对象.方法和属性及类中内置的方法 3.类 是一个模板 ...

  4. C-基本语法与运算

    编译: Technorati 标记: C 1, 编译compilers 命令make 将高级语言转换为低级语言. clang: 1,预处理(preprocessing) 2,编译(complition ...

  5. mysql Table 'performance_schema.session_variables' doesn't exist

    CMD  进入MYSQL的安装目录..Bin 下 执行 mysql_upgrade -u root -p --force 输入密码..然后等待一会儿..会跑一些东西..然后重启服务

  6. 用Redis实现分布式锁 与 实现任务队列(转)

    这一次总结和分享用Redis实现分布式锁 与 实现任务队列 这两大强大的功能.先扯点个人观点,之前我看了一篇博文说博客园的文章大部分都是分享代码,博文里强调说分享思路比分享代码更重要(貌似大概是这个意 ...

  7. 获取Executor提交的并发执行的任务返回结果的两种方式/ExecutorCompletionService使用

    当我们通过Executor提交一组并发执行的任务,并且希望在每一个任务完成后能立即得到结果,有两种方式可以采取: 方式一: 通过一个list来保存一组future,然后在循环中轮训这组future,直 ...

  8. 安装使用ubuntu和opensuse

    liquid: n.液体, adj. 液体的, 流动的 liquidate: v. 清洗; 清算; 变现; 杀戮; weird: [wi2d] e:i, ir:2 离奇的,古怪的... 英文名称, 直 ...

  9. 该不该用inline-block取代float? inline和float的区别?

    该不该用inline-block取代float? 请看这篇文章引用: jtyjty99999的博客 让块级元素 水平排列的通常方式是float, 但是float可能会带来很多意外的问题 可以考虑用in ...

  10. Myeclipse右键新建项目突然变的很少

    额,很是焦躁,最后在界面的右上方点Myeclipse Java enterprise变回原来模样