leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0275.cpp (474B)


0 class Solution {
1 public:
2 int hIndex(const vector<int> &citations) const {
3 const int n = size(citations);
4 int low = 0, high = n - 1;
6 while (low <= high) {
7 const int mid = low + (high - low) / 2;
8 if (citations[mid] == n - mid) return citations[mid];
9 if (citations[mid] > n - mid)
10 high = mid - 1;
11 else
12 low = mid + 1;
13 }
15 return n - high - 1;
16 }
17 };