c++
class Solution {
public:
int hIndex(vector<int>& citations) {
if (citations.empty()) return 0;
//sort(citations.begin(), citations.end());
int n = citations.size();
int st = 0;
int ed = n - 1;
int res = 0;
while (st <= ed) {
int mid = (st + ed) / 2;
if (citations[mid] >= n - mid) {
res = n - mid;
ed = mid - 1;
}
else {
st = mid + 1;
}
}
return res;
}
};