Skip to content

Latest commit

 

History

History
26 lines (24 loc) · 558 Bytes

275.md

File metadata and controls

26 lines (24 loc) · 558 Bytes

275. H-Index II

Solution 1 (time O(log(n)), space O(1))

class Solution {
public:
    int hIndex(vector<int>& citations) {
        int n = citations.size();
        int left = 0;
        int right = n - 1;
        while (left < right) {
            int mid = (left + right) / 2;
            if (citations[mid] >= n - mid) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        if (citations[right] < n - right) {
            return 0;
        }
        return n - right;
    }
};