Leetcode 275. H-Index II

Problem

Given an array of integers citations where citationsi 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 小时前
LeetCode2461~2480题目解析
java·leetcode
文丑颜不良啊4 小时前
LeetCode2441~2460题目解析
java·leetcode
文丑颜不良啊5 小时前
LeetCode2521~2540题目解析
java·leetcode
lisw056 小时前
Dayhoff的PAM替换矩阵理论评介!
线性代数·算法·矩阵
一起学安全技术6 小时前
拆大模型 03|注意力的一句话版本:不用论文讲清 Attention
深度学习·算法·语言模型·transformer
Delightrs8 小时前
Rust LeetCode238 算法题解
开发语言·算法·rust
自信150413057598 小时前
重生之从0开始学习c++之——vector-中篇
c++·学习·算法
文丑颜不良啊8 小时前
LeetCode2501~2520题目解析
java·leetcode
GoAI19 小时前
DeepSeek Harness Memory (一)主流记忆插件总结
后端·算法·面试