Description
Submission
class Solution { public: int hIndex(vector<int>& citations) { int n = citations.size(); sort(citations.begin(), citations.end()); int lower = 0, upper = n; while(lower < upper) { int mid = lower + (upper - lower) / 2; // h-index guess if(n - 1 >= mid && citations[n - 1 - mid] > mid) { lower = mid + 1; } else { upper = mid; } } return lower; } }; // 3,0,6,1,5 // mid n // 0 1 3 5 6 // 0 1 2 // 1 1 3