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 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?

Runtime: 32 ms, faster than 54.70% of C++ online submissions for H-Index II.

#include <vector>
using namespace std;
class Solution {
public:
int hIndex(vector<int>& citations) {
int mid = , left = , right = citations.size();
while(left < right){
mid = left + (right - left) / ;
if(citations.size() - mid > citations[mid] ){
left = mid+;
}else right = mid;
}
return citations.size() - left;
}
};

LC 275. H-Index II的更多相关文章

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

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

  2. Java实现 LeetCode 275 H指数 II

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

  3. Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵

    H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...

  4. 275 H-Index II H指数 II

    这是 H指数 进阶问题:如果citations 是升序的会怎样?你可以优化你的算法吗? 详见:https://leetcode.com/problems/h-index-ii/description/ ...

  5. [LeetCode] 275. H-Index II H指数 II

    Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize ...

  6. leetcode@ [274/275] H-Index & H-Index II (Binary Search & Array)

    https://leetcode.com/problems/h-index/ Given an array of citations (each citation is a non-negative ...

  7. [Swift]LeetCode275. H指数 II | H-Index II

    Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a ...

  8. [LC] 45. Jump Game II

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

  9. Lintcode: Permutation Index II

    Given a permutation which may contain repeated numbers, find its index in all the permutations of th ...

随机推荐

  1. Linux部署tomcat服务常用命令

    cd / 转到根目录 ps -ef|grep tomcat查看进程 ./bin/shutdown.sh 关闭 rm -r logs/* 清除日志 ps -ef|grep tomcat查看进程 ./bi ...

  2. Delphi 编写线程的清除代码

  3. Oracle笔记(十四) 用户管理

    SQL语句分为三类:DML.DDL.DCL,之前已经讲解完了DML和DDL,现在就差DCL操作的,DCL主要表示的是数据库的控制语句,控制的就是操作权限,而在DCL之中,主要有两个语法:GRANT.R ...

  4. Oracle笔记(十一) 建表、更新、查询综合练习

    有某个学生运动会比赛信息的数据库,保存了如下的表: 运动员sporter(运动员编号sporterid,运动员姓名name,运动员性别sex,所属系号department) 项目item(项目编号it ...

  5. 使用Response下载(支持任何格式)

    使用Response下载 下面代码: protected void Button2_Click(object sender, EventArgs e) { Response.ContentType = ...

  6. zencart单独屏蔽左右边栏代码

    1.屏蔽左栏:打开模板目录下的tpl_main_page.php文件,找到以下代码 if (!isset($flag_disable_left) || !$flag_disable_left) { 在 ...

  7. C++踩坑记录(一)std:;string的析构

    之前写服务端程序有一个往消息队列里面推json的过程,然后发现推进去C#端取到的无论如何都是个空指针 简单复现一下现场 string str1 = string("hello1") ...

  8. shell字符串处理

    一.字符串切片: ${#var}:返回字符串变量var的长度${var:offset}:返回字符串变量var中从第offset个字符后(不包括第offset个字符)的字符开始,到最后的部分,offse ...

  9. linux基础_使用指令

    1.指令运行级别 (0)关机 (1)单用户(找回丢失密码) (2)多用户无网络服务 (3)多用户有网络服务 (4)保留 (5)图形界面 (6)重启 /etc/inittab:系统的运行级别配置之文件 ...

  10. zendstudio zenddebug 调试技巧

    毋庸置疑debugger软件减轻了程序员的负担. 最近使用php开发,感觉没有开发C#时的爽快了,原因就是debugger似乎因为商业目的(zend server的原因) zend debugger ...