leetcode-study

274. H-Index

class Solution:
    def hIndex(self, citations: List[int]) -> int:
        """
        Calculate the h-index from a list of citation counts.
        
        The h-index is defined as the maximum value h such that the researcher has published
        at least h papers with each having at least h citations.
        
        Parameters:
            citations (List[int]): A list where each element represents the citation count for a paper.
        
        Returns:
            int: The h-index for the given citation counts.
        """
        # First, sort the citation counts in ascending order.
        citations.sort()
        n = len(citations)  # Total number of papers.
        
        # Iterate over the sorted citations list. 
        # The idea is to find the smallest index i such that the (n - i) papers have at least (n - i) citations.
        for i in range(n):
            h = n - i  # h is the number of papers with citation counts >= current paper's count.
            # Check if the current paper's citation count is at least h.
            if citations[i] >= h:
                return h  # This is the h-index.
        
        # If no such h is found, return 0.
        return 0

Summary of Techniques and Approaches: