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

本文共 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://macta.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
vim使用点滴
查看>>
embedded linux学习中几个需要明确的概念
查看>>
mysql常用语法
查看>>
Morris ajax
查看>>
【Docker学习笔记(四)】通过Nginx镜像快速搭建静态网站
查看>>
ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
查看>>
<转>云主机配置OpenStack使用spice的方法
查看>>
java jvm GC 各个区内存参数设置
查看>>
[使用帮助] PHPCMS V9内容模块PC标签调用说明
查看>>
关于FreeBSD的CVSROOT的配置
查看>>
基于RBAC权限管理
查看>>
数学公式的英语读法
查看>>
留德十年
查看>>
迷人的卡耐基说话术
查看>>
PHP导出table为xls出现乱码解决方法
查看>>
PHP问题 —— 丢失SESSION
查看>>
Java中Object类的equals()和hashCode()方法深入解析
查看>>
数据库
查看>>
dojo.mixin(混合进)、dojo.extend、dojo.declare
查看>>