My O(n) time 11-line JAVA solution


  • 0
    Z
    public int hIndex(int[] citations){
            Arrays.sort(citations);
            int h = 0;
            for(int i=0;i<citations.length;i++){
                int cur = citations[i];
                int smallerThan = citations.length - i;
                if(smallerThan <= cur)h = Math.max(h,smallerThan);
            }
            return h;
        }
    

Log in to reply
 

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