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
相关推荐
别学LeetCode16 小时前
#leetcode# 、
leetcode
青铜发条16 小时前
【算法】常见校验算法对比
算法·信息与通信·校验
LinHenrY122717 小时前
初识C语言(数据在内存中的存储)
c语言·开发语言·算法
R-G-B17 小时前
BM53 缺失的第一个正整数,哈希表,原地哈希(扩展思路)
算法·哈希算法·哈希表·原地哈希
AI科技星17 小时前
观察者与宇宙:描述如何创造物理实在
数据结构·人工智能·算法·机器学习·重构
发疯幼稚鬼17 小时前
简单介绍二项队列及其实现
c语言·数据结构·算法
一只乔哇噻17 小时前
java后端工程师+AI大模型开发进修ing(研一版‖day62)
java·开发语言·算法·语言模型
子一!!17 小时前
并查集(Union-Find)数据结构
java·数据结构·算法
阿正的梦工坊17 小时前
R-Zero:从零数据自进化推理大语言模型
人工智能·算法·语言模型·大模型·llm
Evand J17 小时前
【信号处理课题推荐】小波变化:原理、演进与时频分析应用,MATLAB代码示例
算法·matlab·信号处理·傅里叶分析·傅立叶分析·小波变化