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

python leetcode 274. H-Index

class Solution:
    def hIndex(self, citations):
        """
        :type citations: List[int]
        :rtype: int
        """
        citations.sort()
        n = len(citations)
        l=0
        r=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