题目:
解答:
1 class Solution { 2 public: 3 int hIndex(vector<int>& citations) 4 { 5 int n = citations.size(); 6 7 int pivot; 8 int left = 0; 9 int right = citations.size() - 1; 10 11 while (left <= right) 12 { 13 pivot = left + (right - left) / 2; 14 if (citations[pivot] == n - pivot) 15 { 16 return n - pivot; 17 } 18 else if (citations[pivot] < n - pivot) 19 { 20 left = pivot + 1; 21 } 22 else 23 { 24 right = pivot - 1; 25 } 26 } 27 return n - left; 28 } 29 };
原文:https://www.cnblogs.com/ocpc/p/12830370.html