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
相关推荐
IronMurphy1 天前
【算法三十九】994. 腐烂的橘子
算法
Ares-Wang1 天前
算法》》旅行商问题 TSP、7座桥问题 哈密顿回路 深度优先 和 宽度优先
算法·深度优先·宽度优先
Liqiuyue1 天前
Transformer:现代AI革命背后的核心模型
人工智能·算法·机器学习
WolfGang0073211 天前
代码随想录算法训练营 Day34 | 动态规划 part07
算法·动态规划
Kk.08021 天前
Linux(十一)fork实例练习、文件操作示例及相关面试题目分享
linux·运维·算法
潇冉沐晴1 天前
2026CCCC第三次模拟赛 部分题解
算法
WolfGang0073211 天前
代码随想录算法训练营 Day32 | 动态规划 part05
算法·动态规划
碧海银沙音频科技研究院1 天前
1-1杰理蓝牙SOC的UI配置开发方法
人工智能·深度学习·算法
啊我不会诶1 天前
2024CCPC长春邀请赛
算法