0%

274.H指数

计数排序+后缀和

时间复杂度$O(n)$

空间复杂度$O(n)$

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public int hIndex(int[] citations) {
int n = citations.length;
int[] cnt = new int[n + 1];
for (int x : citations) {
x = x > n ? n : x; // 截断
cnt[x]++;
}
int ans = 0, sufSum = 0;
for (int i = n; i > 0; --i) {
sufSum += cnt[i];
ans = Math.max(ans, Math.min(i, sufSum)); // 引用书和论文量均不小于
}
return ans;
}
}