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
相关推荐
Yupureki11 小时前
《算法竞赛从入门到国奖》算法基础:搜索-记忆化搜索
c语言·c++·学习·算法·深度优先
June bug11 小时前
(#数组/链表操作)合并两个有重复元素的无序数组,返回无重复的有序结果
数据结构·python·算法·leetcode·面试·跳槽
普贤莲花11 小时前
取舍~2026年第4周小结---写于20260125
程序人生·算法·leetcode
curry____30311 小时前
menset的使用方法
算法
苦藤新鸡11 小时前
39.二叉树的直径
算法·leetcode·深度优先
TracyCoder12311 小时前
LeetCode Hot100(6/100)——15. 三数之和
算法·leetcode
bubiyoushang88811 小时前
基于传统材料力学势能法的健康齿轮时变啮合刚度数值分析
人工智能·算法
星火开发设计11 小时前
const 指针与指针 const:分清常量指针与指针常量
开发语言·c++·学习·算法·指针·const·知识
闻缺陷则喜何志丹11 小时前
【树 链 菊花】P10418 [蓝桥杯 2023 国 A] 相连的边|普及+
c++·算法·蓝桥杯···菊花
ygklwyf12 小时前
JPRS编程竞赛2026#1(AtCoder初学者竞赛442)
c++·算法·模拟