class Solution {
public:
int hIndex(vector<int>& citations) {
int h=1;
bool flag=true;
int co=0;
int s=citations.size();
sort(citations.begin(),citations.end(),greater<int>());
if(citations[0]==0)
return 0;
else if(citations[0]==1)
return 1;
while(h<=s&&h<=citations[h-1])
{
h++;
}
return h-1;
}
};
先排序,然后尝试h的值,不太熟练,边界处理时间有点长