首页 > 其他 > 详细

【二分查找】275. H指数 II

时间:2020-05-05 16:48:10      阅读:61      评论:0      收藏:0      [点我收藏+]

题目:

技术分享图片

 

 

 

解答:

技术分享图片

 

 

 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 };

 

【二分查找】275. H指数 II

原文:https://www.cnblogs.com/ocpc/p/12830370.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!