最大最小值问题,应该是对总共的论文数作二分答案,但是昨天周赛写了对最高引用次数作二分的代码,懒得再写了。。
class Solution:
def hIndex(self, citations: List[int]) -> int:
if len(citations) == 0:
return 0
l, r = 0, citations[-1]
ans = []
while l < r:
mid = (l + r) >> 1
t = len(citations) - bisect_left(citations, mid)
if t >= mid:
l = mid + 1
if t < mid:
r = mid
t = len(citations) - bisect_left(citations, r)
return r if t >= r else l - 1