class Solution(object):
def hIndex(self, citations):
x=len(citations)
l,r=0,len(citations)-1
if citations[r]==0:
return 0
while l<=r:
mid=l+r+1>>1
y=x-mid
if (mid-1>=0 and citations[mid-1]<=y and citations[mid]>=y):
return y
elif (mid-1<0 and citations[0]<=y and citations[mid]>=y):
return y
elif citations[mid-1]>y:
r=mid-1
elif citations[mid]<y:
l=mid+1
写的有点复杂,但是还是二分的思想