博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
275. H-Index II
阅读量:7038 次
发布时间:2019-06-28

本文共 1660 字,大约阅读时间需要 5 分钟。

Given an array of citations sorted in ascending order (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 = [0,1,3,5,6]Output: 3 Explanation: [0,1,3,5,6] means the researcher has 5 papers in total and each of them had received 0, 1, 3, 5, 6 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.

Follow up:

This is a follow up problem to H-Index, where citations is now guaranteed to be sorted in ascending order.

Could you solve it in logarithmic time complexity?

难度: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 II.

Memory Usage: 43 MB, less than 6.00% of Java online submissions for H-Index II.

class Solution {    public int hIndex(int[] citations) {        if (null == citations || citations.length < 1) {            return 0;        }        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;    }}

转载地址:http://nrnal.baihongyu.com/

你可能感兴趣的文章
cnetos6上实现nfs共享
查看>>
若是在做销售源码生意的,还是用 VS2008 省事一些,今天有一个客户没 VS2010 只好再把程序倒退回来...
查看>>
.NET大型C/S系统可动态设置登录窗口的实现参考
查看>>
磁盘的读写原理
查看>>
转-快速编辑Shell命令行
查看>>
【中医养生门户网】注意!春分在于“生、升”,保肝促阳为重
查看>>
SQL 语句技巧--聚合函数的灵活使用
查看>>
Java调用SQL Server的存储过程详解
查看>>
springmvc - SqlSession
查看>>
Json 简介
查看>>
zip()方法对数组进行重新组合
查看>>
60-高级路由:IPv6 静态路由
查看>>
40. Combination Sum II
查看>>
关于适配这件小事的前世今生
查看>>
稳压电源中的谐振变频器的特征
查看>>
修改Centos7的网卡名称ens160、eno192改为eth0、eth1
查看>>
VC+ADO 连接ACCESS和SQL SERVER的方法
查看>>
LOGO設計價格 之 全面解說和如何選擇 【原創】
查看>>
Python介绍与特点(自学python知识整理)
查看>>
stimulsoft入门教程:报表与页面上的图表(一)
查看>>