1. H-Index II

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?

h-index:和爱丁顿数一个定义。对于一个从小到大排列好的数组,h-index为:

\[h = \arg \max \{nums[n-i] >= i\}
\]

最简单是线性搜索,逐一判断即可。在有序数组中,可以使用二分查找

class Solution {
public:
int hIndex(vector<int>& citations) {
int l = 0, r = citations.size()-1;
while(l <= r){
int mid = (l+r)/2;
if(citations.size()-mid == citations[mid])return citations.size()-mid;
if(citations.size()-mid > citations[mid])l = mid+1;
else r = mid-1;
}
return citations.size()-l;
}
};

【刷题-LeetCode】275. H-Index II的更多相关文章

  1. Java实现 LeetCode 275 H指数 II

    275. H指数 II 给定一位研究者论文被引用次数的数组(被引用次数是非负整数),数组已经按照升序排列.编写一个方法,计算出研究者的 h 指数. h 指数的定义: "h 代表"高 ...

  2. Leetcode之二分法专题-275. H指数 II(H-Index II)

    Leetcode之二分法专题-275. H指数 II(H-Index II) 给定一位研究者论文被引用次数的数组(被引用次数是非负整数),数组已经按照升序排列.编写一个方法,计算出研究者的 h 指数. ...

  3. LeetCode刷题------------------------------LeetCode使用介绍

    临近毕业了,对技术有种热爱的我也快步入码农行业了,以前虽然在学校的ACM学习过一些算法,什么大数的阶乘,dp,背包等,但是现在早就忘在脑袋后了,哈哈,原谅我是一枚菜鸡,为了锻炼编程能力还是去刷刷Lee ...

  4. 【leetcode刷题笔记】Word Ladder II

    Given two words (start and end), and a dictionary, find all shortest transformation sequence(s) from ...

  5. 【leetcode刷题笔记】Palindrome Partitioning II

    Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...

  6. 【leetcode刷题笔记】Jump Game II

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  7. C#LeetCode刷题之#598-范围求和 II​​​​​​​(Range Addition II)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3881 访问. 给定一个初始元素全部为 0,大小为 m*n 的矩阵 ...

  8. C#LeetCode刷题之#119-杨辉三角 II(Pascal‘s Triangle II)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3690 访问. 给定一个非负索引 k,其中 k ≤ 33,返回杨辉 ...

  9. 【刷题-LeetCode】264. Ugly Number II

    Ugly Number II Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose ...

随机推荐

  1. 移动应用开发:Flutter

    目录 前言 Flutter 介绍 移动应用开发:选择对比 原生开发 H5 技术 React Native Flutter 总结 参考 前言 "镜子镜子 告诉我,世界上最好的语言是什么&quo ...

  2. CF1469D Ceil Divisions 题解

    Content 你有一个长度为 \(n\) 的数组 \(a\),初始时,\(\forall i\in[1,n]\),\(a_i=i\). 每次操作选择两个数 \(x,y(1\leqslant x,y\ ...

  3. CentOS系统 python3+python2 & Ipython安装

    https://www.cnblogs.com/albertrui/p/8093384.html 一.安装依赖环境 输入命令: yum -y install zlib-devel bzip2-deve ...

  4. Spring学习(四)在Web项目中实例化IOC容器

    1.前言 前面我们讲到Spring在普通JAVA项目中的一些使用.本文将介绍在普通的Web项目中如何实例化Spring IOC容器.按照一般的思路.如果在Web中实例化Ioc容器.这不得获取Conte ...

  5. Lucene 基础数据压缩处理

    Lucene 为了使的信息的存储占用的空间更小,访问速度更快,采取了一些特殊的技巧,然 而在看 Lucene 文件格式的时候,这些技巧却容易使我们感到困惑,所以有必要把这些特殊 的技巧规则提取出来介绍 ...

  6. 1281 - New Traffic System

    1281 - New Traffic System   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  7. 教学日志:javaSE-面向对象1

    对象,类,属性,方法的理解 package com.tengxun.class6.oop1; /** * @Auther: Yu Panpan * @Date: 2021/12/7 - 12 - 07 ...

  8. 由于ios由UIWebView换成了WKWebview内核后导致webview请求接口文件上传,后台接收不到文件

    2020年4月起App Store将不再接受使用UIWebView的新App上架.2020年12月起将不再接受使用UIWebView的App更新. 解决后台文件接收不到的问题 function GLA ...

  9. Java初学者作业——编写JAVA程序,要求输入技术部门5位员工的理论成绩和实操成绩,计算并输出各位员工的最终评测成绩。

    返回本章节 返回作业目录 需求说明: 某软件公司要求对技术部门的所有员工进行技能评测,技术评测分为两个部分:理论部分以及实操部分,最终评测成绩=理论成绩×0.4+实操成绩×0.6,要求输入技术部门5位 ...

  10. netty系列之:netty对SOCKS协议的支持

    目录 简介 SocksMessage Socks4Message Socks5Message 总结 简介 SOCKS是一个优秀的网络协议,主要被用来做代理,它的两个主要版本是SOCKS4和SOCKS5 ...