当前位置:   article > 正文

Leetcode 274. H-Index

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/493447
推荐阅读
相关标签
  

闽ICP备14008679号