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
相关推荐
2401_8384725110 小时前
C++图形编程(OpenGL)
开发语言·c++·算法
-dzk-10 小时前
【代码随想录】LC 203.移除链表元素
c语言·数据结构·c++·算法·链表
进击的小头10 小时前
陷波器实现(针对性滤除特定频率噪声)
c语言·python·算法
知无不研10 小时前
冒泡排序算法
算法·冒泡排序·排序
毅炼10 小时前
hot100打卡——day17
java·数据结构·算法·leetcode·深度优先
Tisfy10 小时前
LeetCode 3010.将数组分成最小总代价的子数组 I:排序 OR 维护最小次小
算法·leetcode·题解·排序·最小次小值
Learn Beyond Limits10 小时前
文献阅读:A Probabilistic U-Net for Segmentation of Ambiguous Images
论文阅读·人工智能·深度学习·算法·机器学习·计算机视觉·ai
m0_7369191011 小时前
编译器命令选项优化
开发语言·c++·算法
naruto_lnq11 小时前
C++中的工厂方法模式
开发语言·c++·算法
千逐-沐风11 小时前
SMU-ACM2026冬训周报2nd
算法