Share my AC java solution


  • 0
    J
    public class Solution {
    public int hIndex(int[] citations) {
        if(citations.length==0 || citations==null) return 0;
        int left=0, right=citations.length-1, result=0;
        while(left<=right){
            int mid=left+(right-left)/2;
            if(citations[mid]>=(citations.length-mid)){
                result=Math.max(result, citations.length-mid);
                right=mid-1;
            }else{
                left=mid+1;
            }
        }
        return result;
    }
    

    }


Log in to reply
 

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