AC Python 48 ms solution, O(log n)


  • 1
    def hIndex(self, citations):
        r = n = len(citations)
        l = 0
        while l != r:
            m = (l + r) >> 1
            if citations[m] == n - m:
                return n - m
            if citations[m] > n - m:
                r = m
            else:
                l = m + 1
        return n - l
    
    # 82 / 82 test cases passed.
    # Status: Accepted
    # Runtime: 48 ms
    

    Just simple binary search.


Log in to reply
 

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