O(n) time complexity and space usage


  • 0
    J
    public class Solution {
    public int hIndex(int[] citations) {
        int[] sum = new int[citations.length + 2];
        for(int c : citations){
            int index = c >= citations.length ? citations.length : c;
            sum[index]++;
        }
        for(int i = sum.length - 2; i >= 0; i--){
            sum[i] += sum[i + 1];
            if(sum[i] >= i)
                return i;
        }
        return 0;
    }
    

    }


Log in to reply
 

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