Leetcode 275. H-Index II

Problem

Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper and citations is sorted in ascending order, 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.

You must write an algorithm that runs in logarithmic time.

Algorithm

Bineary search.

Code

python3 复制代码
class Solution:
    def hIndex(self, citations: List[int]) -> int:
        K = len(citations)
        if 1 == K:
            return (citations[0] >= 1) * 1
        
        L, R, = 0, len(citations) - 1
        while L < R:
            Mid = (L + R) // 2
            if citations[Mid] >= K - Mid:
                R = Mid
            else: L = Mid + 1

        while L <= R and citations[L] < K - L:
            L += 1
        return K - L
相关推荐
蚊子码农3 小时前
算法题解记录--239滑动窗口最大值
数据结构·算法
liliangcsdn3 小时前
A3C算法从目标函数到梯度策略的探索
算法
陈天伟教授3 小时前
人工智能应用- 材料微观:06.GAN 三维重构
人工智能·神经网络·算法·机器学习·重构·推荐算法
liliangcsdn4 小时前
A3C强化学习算法的探索和学习
算法
Figo_Cheung4 小时前
Figo《量子几何学:从希尔伯特空间到全息时空的统一理论体系》(二)
算法·机器学习·几何学·量子计算
额,不知道写啥。4 小时前
HAO的线段树(中(上))
数据结构·c++·算法
LYS_06185 小时前
C++学习(5)(函数 指针 引用)
java·c++·算法
紫陌涵光5 小时前
669. 修剪二叉搜索树
算法·leetcode
NGC_66115 小时前
二分查找算法
java·javascript·算法