O(n) 5-lines 1ms Concise Code

  • 2
    public int hIndex(int[] citations) {
            int n = citations.length, h = n, sum;
            int[] cnt = new int[n + 1];
            for (int c : citations) cnt[Math.min(n, c)]++;
            for (h = n, sum = cnt[n]; sum < h; sum += cnt[--h]);
            return h;

Log in to reply

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