其他分享
首页 > 其他分享> > leetcode275

leetcode275

作者:互联网

 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

这题做起来感觉很糟。

标签:search,idx,mid,len,这题,citations,leetcode275
来源: https://www.cnblogs.com/asenyang/p/12640536.html