题目
Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.
According to the definition of h-index on Wikipedia: “A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each.”
解题思路
- 排序+二分,具体参见H-Index II
- 按引用次数进行基数排序,如果次数超过n就看做n,最后向前扫一遍,找到hindex
代码
class Solution:
def hIndex(self, citations: List[int]) -> int:
n = len(citations)
paper = [0] * (n + 1)
for c in citations:
paper[min(n, c)] += 1
s, h = paper[-1], n
while h > s:
h -= 1
s += paper[h]
return h