Standard Binary Search Solution


  • 0
    E
    public class Solution {
    public int hIndex(int[] citations) {
        int left = 0;
        int L = citations.length;
        int right = L-1;
        while(left <= right) {
            int mid = left + (right-left)/2;
            if(citations[mid] < L-mid)
                left = mid+1;
            else if(citations[mid] > L-mid)
                right = mid-1;
            else
                return citations[mid];
        }
        return L-left;
    }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.