Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int hIndex(vector<int>& citations) {
- int n = citations.size();
- int left = 0, right = n - 1;
- while (left <= right) {
- int mid = left + (right - left) / 2;
- int h = n - mid;
- if (citations[mid] == h) {
- return h;
- } else if (citations[mid] < h) {
- left = mid + 1;
- } else {
- right = mid - 1;
- }
- }
- return n - left;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement