边工作边刷题:70天一遍leetcode: day 57

H-Index I/II

要点:

class Solution(object):
    def hIndex(self, citations):
        """
        :type citations: List[int]
        :rtype: int
        """
        if not citations: return 0
        n = len(citations)
        low,high=0, n-1
        mid = low + (high-low)/2
        while low < high:
            if citations[mid]>=n-mid:
                high = mid
            else:
                low = mid+1
            mid = low + (high-low)/2
            
        return n-mid if citations[mid]>=n-mid else 0 

posted @ 2016-06-16 04:46  absolute100  阅读(86)  评论(0编辑  收藏  举报