O(n) with java(1 ms)


  • -2
    S
    public int hIndex(int[] citations) {
        int n = citations.length;
        int[] hindex = new int[n + 1];
        for(int val: citations){
            if(val >= n) hindex[n]++;
            else hindex[val]++;
        }
        int sum = 0;
        for(int i = n; i > 0; i--){
            sum += hindex[i];
            if(i <= sum){
                sum = Math.max(i, sum - hindex[i]);
                break;
            }
        }
        return sum;
    }

Log in to reply
 

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