Python Binary Search Solution


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

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.