# LeetCode:H-Index II

### H-Index II

Total Accepted: 24331 Total Submissions: 74459 Difficulty: Medium

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

Hint:

1. Expected runtime complexity is in O(log n) and the input is sorted.

Subscribe to see which companies asked this question

java code:

public class Solution {
public int hIndex(int[] citations) {

if(citations == null || citations.length == 0) return 0;

int len = citations.length;
int lo = 0, hi = len-1;

while(lo <= hi) {
int mid = lo + (hi-lo)/2;

if(citations[mid] == len - mid)
return len-mid;
else if(citations[mid] >= len - mid)
hi = mid - 1;
else
lo = mid + 1;
}

return len-lo;
}
}

#### [leetcode] 275.H-Index II

2015-09-05 17:00:53

#### [leetcode-275]H-Index II(java)

2015-09-06 08:57:22

#### LeetCode——H-Index

2015-09-04 10:05:45

#### leetcode笔记：H-Index

2016-02-01 15:31:09

#### [leetcode] 274.H-Index

2015-09-05 16:58:02

#### [LeetCode] 274. H-Index 解题报告

2017-02-20 00:47:26

#### leetcode之H-index &&H-index II

2016-02-28 10:23:08

#### LeetCode H-index and H-index II

2015-12-18 14:38:25

#### leecode 解题总结：275. H-Index II

2017-02-28 13:59:36

#### H-Index II | Java最短代码实现

2016-03-14 14:47:35