public int hIndex2(int[] citations) {
        if (citations == null) return 0;
        int n = citations.length;
        int[] cnts = new int[n + 1];
        for (int c : citations) {
            ++cnts[c >= n ? n : c];
        }
        int paperCnt = 0;
        for (int i = n; i >= 0; --i) {
            paperCnt += cnts[i];
            if (paperCnt >= i) return i;
        }
        return 0;
    }