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
相关推荐
Freedom_my7 分钟前
插入排序算法
数据结构·算法·排序算法
9523610 分钟前
排序-算法
数据结构·算法·排序算法
WongKyunban11 分钟前
插入排序的原理和示例
数据结构·算法·排序算法
flashlight_hi28 分钟前
LeetCode 分类刷题:404. 左叶子之和
javascript·算法·leetcode
小白程序员成长日记1 小时前
2025.11.19 力扣每日一题
算法·leetcode·职场和发展
迈巴赫车主2 小时前
蓝桥杯 20541魔法科考试
java·数据结构·算法·蓝桥杯
star learning white3 小时前
xmC语言8
c语言·开发语言·算法
青小俊3 小时前
【代码随想录c++刷题】-二分查找 移除元素 有序数组的平方 - 第一章 数组 part 01
c++·算法·leetcode
ytttr8733 小时前
基于MATLAB实现晶体共晶凝固模拟
开发语言·算法·matlab
倦王4 小时前
力扣日刷251120
算法·leetcode·职场和发展