计数排序+后缀和
把引用次数按 0..n 计数(大于 n 的统一记为 n),再从大到小累加后缀和。后缀和表示引用数不少于 i 的论文数量,与 i 取较小值即为候选 H 指数。
时间复杂度
空间复杂度
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; } }
|