```
class Solution {
public:
int hIndex(vector<int>& citations) {
if(citations.size()==0)return 0;
sort(citations.begin(),citations.end(),[](const int &a,const int &b){return a>b;});
for(int i=citations.size()-2;i>=0;--i){
if(citations[i]>i && citations[i+1]<=i+1)return i+1;
}
if(citations.back()>=citations.size())return citations.size();
return 0;
}
};
```