1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public: int hIndex(vector<int>& citations) { int n = citations.size(), l = 0, r = n; auto check = [&](int h) { int idx = lower_bound(citations.begin(), citations.end(), h) - citations.begin(); return n - idx >= h; }; while (l < r) { int mid = l + r + 1 >> 1; if (check(mid)) l = mid; else r = mid - 1; } return l; } };
|