Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper and citations&nbsp;is sorted in an ascending order, return compute the researcher's h-index.

According to the definition of h-index on Wikipedia: A scientist has an index h if h of their n papers have at least h citations each, and the other n − h papers have no more than h citations each.

If there are several possible values for h, the maximum one is taken as the h-index.

You must write an algorithm that runs in logarithmic time.

&nbsp;
Example 1:

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, their h-index is 3.


Example 2:

Input: citations = [1,2,100]
Output: 2


&nbsp;
Constraints:


	n == citations.length
	1 &lt;= n &lt;= 105
	0 &lt;= citations[i] &lt;= 1000
	citations is sorted in ascending order.


import bisect

class Solution:
    def hIndex(self, citations: List[int]) -> int:
        n = len(citations)
        for h in range(n, -1, -1):
            if h <= n - bisect.bisect_left(citations, h):
                return h
class Solution {
    public int hIndex(int[] citations) {
        int n=citations.length;
        int res=0;
        for(int i=0;i<n;i++)
        {
            if(citations[i]>=n-i)
            {
                return n-i;
            }
        }
        return res;
    }
}
class Solution {
public:
    int hIndex(vector<int>& citations) {
        int start = 0 , end = citations.size()-1;
        int n = citations.size();
        while(start <= end){
            int mid = start + (end - start) / 2;
            int val = citations[mid];
            if(val == (n - mid)) return citations[mid];
            else if(val < n - mid){
                start = mid + 1;
            }
            else{
                end = mid - 1;
            }
        }
        return n - start;
    }
};
/**
 * The binary search solution.
 * 
 * Time Complexity:  O(log(n))
 * Space Complexity: O(1)
 * 
 * @param {number[]} citations
 * @return {number}
 */
var hIndex = function(citations) {
	const n = citations.length

	let l = 0
	let r = n - 1

	while (l <= r) {
		const m = Math.floor((l + r) / 2)

		if (citations[m] > n - m) {
			r = m - 1
			continue
		}

		if (citations[m] < n - m) {
			l = m + 1
			continue
		}

		return citations[m]
	}

	return n - l
}
H-Index II