时间轴
时间轴
2025-10-03
init
计数排序
题目:
排序后,此时 citations[i]表示有 n-i 个论文大于等于 citations[i],我们直接遍历 h 找最大值即可
12345678910111213141516171819202122232425 | using std::vector;class Solution { public: // 一名科研人员的 h 指数 是指他(她)至少发表了 h 篇论文 // 并且 至少 有 h 篇论文被引用次数大于等于 h 。如果 h 有多种可能的值,h 指数 // 是其中最大的那个。 int hIndex(vector<int> &citations) { int n = citations.size(); int h = 0; std::sort(citations.begin(), citations.end()); for (int i = 1; i <= n; i++) { // 遍历h if (citations[n - i] >= i) { h = i; } } return h; }}; |
