class Solution {
public:
int hIndex(vector<int>& citations) {
std::sort(citations.begin(), citations.end());
int n = citations.size();
for (int i = n - 1; i >= 0; --i) {
if (citations[i] < n - i)
return n - i - 1;
}
return n;
}
};
class Solution {
public:
int hIndex(vector<int>& nums) {
int n = nums.size(), total = 0;
vector<int> count(n + 1, 0);
for (int i = 0; i < n; ++i) {
if (nums[i] < n + 1)
count[nums[i]]++;
else
count[n]++;
}
for (int i = n; i >= 0; --i) {
if (count[i]) total += count[i];
if (total >= i) return i;
}
return 0;
}
};