# 0275. H-Index II ###### tags: `Leetcode` `Medium` `Binary Search` Link: https://leetcode.com/problems/h-index-ii/description/ ## 思路 ### Binary Search binary search h index 对于每一个```h```我们要检查到底有多少篇paper的citation大于等于```h``` 这部分也可以用binary search解决 之所以在line4 把end设成```n+1```是因为有可能```h```是答案 所以我们必须要让```start```最大值是```n+1``` ## Code ```java= class Solution { public int hIndex(int[] citations) { int n = citations.length; int start = 0, end = n+1; while(start<end){ int mid = start+(end-start)/2; if(numOfPaper(mid, citations)>=mid){ start = mid+1; } else end = mid; } return start-1; } private int numOfPaper(int h, int[] citations){ int n = citations.length; int start = 0, end = n; while(start<end){ int mid = start+(end-start)/2; if(citations[mid]<h){ start = mid+1; } else end = mid; } return n-start; } } ```