数组已经有序,直接二分即可,参考上一题1768. H 指数
class Solution {
public:
int hIndex(vector<int>& citations) {
int n = citations.size();
int l = 0, r = n;
while (l < r)
{
int mid = l + r + 1 >> 1;
if (citations[n - mid] >= mid) l = mid;
else r = mid - 1;
}
return r;
}
};