274 - H-Index

解法

先用 cnt[i] 被 cite 過 i 次的文章總共有幾個,再用再由後向前更新。
就可以知道 >= i 的 paper 有多少,再來判斷。

程式碼

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public:
int hIndex(vector<int>& citations) {
int cnt[1020];
for(int i = 0; i < 1020; i++) cnt[i] = 0;

for(int i = 0; i < citations.size(); i++){
cnt[citations[i]]++;
}

for(int i = 1000; i >= 1; i--){
cnt[i-1] += cnt[i];
if(cnt[i] >= i) return i;
}
return 0;
}
};
  • 版權聲明: 本部落格所有文章除有特別聲明外,均採用 Apache License 2.0 許可協議。轉載請註明出處!
  • © 2020-2024 John Doe
  • Powered by Hexo Theme Ayer
  • PV: UV: