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. bootstrapTable post提交数据,后台无法接收的问题

    解决方法:contentType:"application/x-www-form-urlencoded; charset=UTF-8",

  2. mysql主从同步监控---邮件告警

    #!/bin/bash #check MySQL_Slave Status #crontab time : MYSQLPORT=`netstat -na|grep "|awk -F[:&qu ...

  3. C# 接口的作用浅谈举例(转)

    转:http://blog.csdn.net/liuqinghui1990/article/details/77171051 我初次接触接口(Interface),对接口的作用有点迷茫,C#接口中包含 ...

  4. 挺棒的七个Python图形应用GUI开发框架

    作为Pyhon开发者,你迟早都会碰到图形用户界面(GUI)应用开发任务,目前市场上有大量Python GUI开发框架可供选择,Python wiki GUI programming给出了超过30个跨平 ...

  5. 简单的理解 StringBuffer/StringBuilder/String 的区别

    StringBuffer/StringBuilder/String 的区别 这个三类之间主要的区别:运行速度,线程安全两个方面. 速度方面(快到慢): StringBuilder > Strin ...

  6. 2018-2019 ACM-ICPC Brazil Subregional Programming Contest B. Marbles(博弈)

    题目链接:https://codeforc.es/gym/101908/problem/B 题意:两个人玩游戏,有 n 块石头,初始坐标为(x,y),一次操作可以将一块石头移动到(x - u,y),( ...

  7. 题解 BZOJ1026 & luogu P2657 [SCOI2009]windy数 数位DP

    BZOJ & luogu 看到某大佬AC,本蒟蒻也决定学习一下玄学的数位$dp$ (以上是今年3月写的话(叫我鸽神$qwq$)) 思路:数位$DP$ 提交:2次 题解:(见代码) #inclu ...

  8. JS 定时器-setInterval、clearInterval、setTimeout

    在微信小程序里写的: // pages/splash/splash.js const app = getApp() Page({ data: { remainSecond: }, // 页面渲染完成后 ...

  9. vue-cli 本地代理 造成session丢失 而登录不上去 解决办法

    本地代理造成session丢失,登录不成功,是由于代理配置造成的 devServer: { port: 8000, proxy:{ '/qiantai':{ target:'线上地址/qiantai' ...

  10. Appium进阶教程

    Monkey的使用 adb shell monkey -p com.lqr.wechat -v 500 > monkey.log adb shell monkey -p com.lqr.wech ...