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
相关推荐
算法鑫探33 分钟前
闰年判断:C语言实战解析
c语言·数据结构·算法·新人首发
WBluuue44 分钟前
数据结构与算法:康托展开、约瑟夫环、完美洗牌
c++·算法
木子墨5161 小时前
LeetCode 热题 100 精讲 | 并查集篇:最长连续序列 · 岛屿数量 · 省份数量 · 冗余连接 · 等式方程的可满足性
数据结构·c++·算法·leetcode
王老师青少年编程2 小时前
csp信奥赛C++高频考点专项训练之贪心算法 --【线性扫描贪心】:均分纸牌
c++·算法·编程·贪心·csp·信奥赛·均分纸牌
EQUINOX12 小时前
2026年码蹄杯 本科院校赛道&青少年挑战赛道提高组初赛(省赛)第一场,个人题解
算法
萝卜小白2 小时前
算法实习Day04-MinerU2.5-pro
人工智能·算法·机器学习
Liangwei Lin2 小时前
洛谷 P3133 [USACO16JAN] Radio Contact G
数据结构·算法
weixin_513449963 小时前
PCA、SVD 、 ICP 、kd-tree算法的简单整理总结
c++·人工智能·学习·算法·机器人
code_pgf3 小时前
Qwen2.5-VL 算法解析
人工智能·深度学习·算法·transformer
Code-keys3 小时前
Android Codec2 Filter 算法模块开发指南
android·算法·音视频·视频编解码