```
int hIndex(vector<int>& citations) {
if (citations.empty())
return 0;
vector<int> count(citations.size()+1, 0); // record 0-size
for (int i = 0; i < citations.size(); ++i)
{
count[citations[i] < count.size() ? citations[i] : count.size() - 1]++;
}
int sum = 0;
for (int j = count.size() - 1; j >= 0; --j)
{
sum += count[j];
if (j <= sum)
return j;
}
return 0;
}
```