- categories: Code, Interview Question, leetcode, Medium
- source: https://leetcode.com/problems/h-index
- topics: Array
Given an array of integers citations
where citations[i]
is the number of citations a researcher received for their ith
paper, return the researcher’s h-index.
According to the definition of h-index on Wikipedia: The h-index is defined as the maximum value of h
such that the given researcher has published at least h
papers that have each been cited at least h
times.
Idea:
Order by descending and counter
class Solution:
def hIndex(self, citations: List[int]) -> int:
citations.sort(reverse=True)
counter = 0
h = 0
for c in citations:
counter += 1
h = max(h, min(c, counter))
return h