Simple Java Solution, O(1) space and O(n lg n) time


  • 0
    P
    public int hIndex(int[] citations){
        if (citations.length == 0) return 0;
        int h = 0;
        int d;
        
        //O(n log n)
        Arrays.sort(citations);
        
        for(int i = citations.length - 1; i >= 0; i--){
            d = citations.length - i;
            if((citations[i] >= d) && (h < d)) h = d;
        }
        return h;
    }

Log in to reply
 

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