Short O(n) python


  • 0
    N

    observation: by definition, an h-index is at most the number of papers.

    class Solution(object):
        def hIndex(self, citations):
            """
            :type citations: List[int]
            :rtype: int
            """
            l = len(citations)
            count = [0] * (l + 1)
            for c in citations:
                count[min(l, c)] += 1
            sum = 0
            for i in range(l, -1, -1):
                sum += count[i]
                if sum >= i:
                    return i
    

Log in to reply
 

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