leetcode-274.H指数

我这个是不用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:
                continue
            d[i] = d.get(i,0)+1
        for h in range(total+1):
            if h > total:
                h = h - 1
                break 
            if h not in d:
                continue 
            total -= d[h]
        return h
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值