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
相关推荐
qq_4160187214 分钟前
C++与机器学习框架
开发语言·c++·算法
左左右右左右摇晃16 分钟前
数据结构——红黑树
算法
CoovallyAIHub21 分钟前
传感器数据相互矛盾时,无人机蜂群如何做出可靠的管道泄漏检测决策?
算法·架构·无人机
CoovallyAIHub23 分钟前
Claude Code Review:多 Agent 自动审查 PR,代码产出翻倍后谁来把关?
算法·架构·github
jyan_敬言40 分钟前
【算法】高精度算法(加减乘除)
c语言·开发语言·c++·笔记·算法
树獭叔叔1 小时前
内存价格被Google打下来了?: TurboQuant对KVCache的量化
算法·aigc·openai
旖-旎1 小时前
前缀和(矩阵区域和)(8)
c++·算法·leetcode·前缀和·动态规划
月落归舟1 小时前
排序算法---(一)
数据结构·算法·排序算法
liuyao_xianhui1 小时前
优选算法_翻转链表_头插法_C++
开发语言·数据结构·c++·算法·leetcode·链表·动态规划
Book思议-1 小时前
【数据结构实战】循环队列FIFO 特性生成六十甲子(天干地支纪年法),实现传统文化里的 “时间轮回”
数据结构·算法·