1. 程式人生 > >python leetcode 275. H-Index II

python leetcode 275. H-Index II

class Solution:
    def hIndex(self, citations):
        """
        :type citations: List[int]
        :rtype: int
        """
        n = len(citations)
        l,r=0,n-1
        h = 0 
        while l<=r:
            mid=l+(r-l)//2
            h = max(h,min(citations[mid],n-mid))
            if
citations[mid]<n-mid: l=mid+1 else: r=mid-1 return h