首页 > 其他 > 详细

leetcode275

时间:2020-04-06 11:10:24      阅读:54      评论:0      收藏:0      [点我收藏+]
 1 class Solution:
 2     def hIndex(self, citations):
 3         citations_len = len(citations)
 4         if citations_len<=0:
 5             return 0
 6         low = 0
 7         high = citations_len-1
 8         h_idx = 0
 9         while low <= high:
10             mid = (low+high)//2
11             if citations[mid] >= citations_len-mid:
12                 h_idx = citations_len-mid
13                 high = mid-1
14             else:
15                 low = mid+1
16         return h_idx

参考:https://leetcode.com/problems/h-index-ii/discuss/525117/Python-solution-binary-search

这题做起来感觉很糟。

leetcode275

原文:https://www.cnblogs.com/asenyang/p/12640536.html

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