O(logN) Java Solution, 11ms


  • -1
    Y
    public int hIndex(int[] citations) {
        if(citations.length==0) return 0;
        int size=citations.length,begin=0,end=size-1,mid=(begin+end)/2;
        while(begin<=end){
            if(citations[mid]>=size-mid){
                if(mid==0||citations[mid-1]<size-mid+1) return size-mid;
                else end = mid-1;
            }
            else begin = mid+1;
            mid = (begin+end)/2;
        }
        return 0;
    }

Log in to reply
 

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