274. H-Index

栏目: Java · 发布时间: 5年前

内容简介: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

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.

难度:medium

题目:给定一个研究人员的引用数组(每个引用都是一个非负整数),编写一个函数来计算研究人员的h-index。

根据维基百科关于h-index的定义,一个科学家的h-index为h,即其N篇文章中有h篇的引用不低于h, 并且其它文章引用数不超过h.

思路:弄清题义即可。

Runtime: 3 ms, faster than 100.00% of Java online submissions for H-Index.

Memory Usage: 37.2 MB, less than 65.22% of Java online submissions for H-Index.

class Solution {
    public int hIndex(int[] citations) {
        if (null == citations || citations.length < 1) {
            return 0;
        }
        Arrays.sort(citations);
        int n = citations.length;
        int hIndex = 0;
        for (int i = n - 1; i >= 0; i--) {
            if (citations[i] >= n - i) {
                hIndex++;
            } else {
                break;
            }
        }
        
        return hIndex;
    }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

重来

重来

[美] 贾森·弗里德、[丹] 戴维·海涅迈尔·汉森 / 李瑜偲 / 中信出版社 / 2010-10 / 36.00元

大多数的企业管理的书籍都会告诉你:制定商业计划、分析竞争形势、寻找投资人等等。如果你要找的是那样的书,那么把这本书放回书架吧。 这本书呈现的是一种更好、更简单的经商成功之道。读完这本书,你就会明白为什么计划实际上百害而无一益,为什么你不需要外界投资人,为什么将竞争视而不见反倒会发展得更好。事实是你所需要的比你想象的少得多。你不必成为工作狂,你不必大量招兵买马,你不必把时间浪费在案头工作和会议......一起来看看 《重来》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器