我这个是不用sort的方式,所以复杂度是n,但是耗额外空间。
首先,用哈希表存储各个引用量的数量,超出论文数量的引用量可以不存。
然后,从0到论文数量进行对h指数的遍历,当超过论文量时,停止遍历,break掉,找到了h。
h遍历时,更新论文量,把低于h的删掉。
class Solution:def hIndex(self, citations: List[int]) -> int:d = {}total = len(citations)for i in citations:if i > total:continued[i] = d.get(i,0)+1for h in range(total+1):if h > total:h = h - 1break if h not in d:continue total -= d[h]return h