public class Solution {
public int hIndex(int[] citations) {
int start = 0;
int end = citations.length1;
int len = citations.length;
int result = 0;
int mid;
while(start <= end){
mid = start + (endstart)/2;
if(citations[mid] >= (len  mid)){
result = (lenmid);
end = mid1;
}
else{
start = mid + 1;
}
}
return result;
}
}
Simple 13ms Java solution


Why is the condition citations[mid] >= (len  mid) and not citations[mid] == (len  mid)? H index is the biggest number h such that there are h papers with at least h citations, right? so that means for a number to be a valid h index, citations[mid] must equal len  mid, cause len  mid is the # of papers that have at least citations[mid] citations.