Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
19 lines (18 sloc) 492 Bytes
class Solution {
public:
int hIndex(vector<int>& citations) {
int citationNum = citations.size();
if (citationNum == 0) return 0;
sort(citations.begin(), citations.end(), greater<int>());
if (citations[0] == 0) return 0;
int cIdx = 0;
while (cIdx < citationNum) {
if (cIdx + 1 > citations[cIdx]) {
break;
} else {
cIdx++;
}
}
return cIdx;
}
};