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. CF638A Home Numbers 题解

    Content Vasya 的家在一条大街上,大街上一共有 \(n\) 座房子,其中,奇数编号的房子在大街的一侧,从左往右依次编号为 \(1,3,5,7,...,n-1\),偶数编号的房子在大街的另一 ...

  2. CF253A Boys and Girls 题解

    Content 有 \(n\) 个男生.\(m\) 个女生坐在一排,请求出这样一种方案,使得相邻两个座位之间的人的性别不同的次数最多. 数据范围:\(1\leqslant n,m\leqslant 1 ...

  3. Hystrix 监控可视化页面——Dashboard 流监控

    1.什么是Dashboard Hystrix-dashboard 是一款针对 Hystrix 进行实时监控的工具页面,通过 Hystrix Dashboard 我们可以在直观地看到各 Hystrix ...

  4. 点击DIV触发其他元素的点击事件(案例:点击type="radio" 的input 标签外层DIV,触发内部单选点击选中事件)

    方法一: 直接用找到对应dom元素调用.click()方法 $('.user_content').click(function(){ $(this).children()[0].click(); // ...

  5. Linux使用docker安装zimg图片服务器

    官方地址:http://zimg.buaa.us/ 配置文件 zimg.lua --zimg server config --server config --是否后台运行 is_daemon = 1 ...

  6. 【LeetCode】125. Valid Palindrome 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 解题方法 列表生成式 正则表达式 双指针 日期 题目地址:https:/ ...

  7. 记一次引入Elasticsearch的系统架构实战

    前言 我曾经面试安踏的技术岗,当时面试官问了我一个问题:如果你想使用某个新技术但是领导不愿意,你怎么办? 对于该问题我相信大家就算没有面试被问到过,现实工作中同事之间的合作也会遇到. 因此从我的角度重 ...

  8. Exponential family of distributions

    目录 定义 性质 极大似然估计 最大熵 例子 Bernoulli 指数分布 正态分布 Choi H. I. Lecture 4: Exponential family of distributions ...

  9. Geometric GAN

    目录 概 主要内容 McGAN 结合SVM 训练 训练 理论分析 证明 Jae Hyun Lim, Jong Chul Ye, Geometric GAN. 概 很有趣, GAN的训练过程可以分成 寻 ...

  10. Capstone CS5218|CS5218参数|CS5218电路

    Capstone CS5218是一款单端口HDMI/DVI电平移位器/中继器,具有重新定时功能.它支持交流和直流耦合信号高达3.0-Gbps的操作与可编程均衡和抖动清洗.它包括2路双模DP电缆适配器寄 ...