LeetCode - The World's Leading Online Programming Learning Platform

Intuition

The maximum value of the h-index is the length of citations. If the number of citations for any paper is less than the maximum value, the h-index will decrease.

Approach

  1. Sort the citations array.
  2. Set variable h, default is the the maxium h-index (the length of citations).
  3. Go through the sorted citations array, if any paper's citation is less than h, decrease the h by 1.

Complexity

Code

class Solution:
    def hIndex(self, citations: List[int]) -> int:
        citations.sort()
        h = len(citations)
        
        for c in citations:
            if c >= h:
                return h
            h -= 1
        
        return h