Leetcode 274. H-Index

Problem

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.

Algorithm

Sort the citations by the reverse order and calculate the h-index.

Code

class Solution:
    def hIndex(self, citations: List[int]) -> int:
        clen = len(citations)
        citations.sort(reverse = True)
        n = 0
        while n < clen and citations[n] >= n+1:
            n += 1
        return n

你可能感兴趣的:(Leetcode,解题报告,入门题,leetcode,算法,职场和发展)