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
相关推荐
LabVIEW开发4 分钟前
PID控制的优势与LabVIEW应用
算法·labview
涅槃寂雨28 分钟前
C语言小任务——寻找水仙花数
c语言·数据结构·算法
就爱学编程36 分钟前
从C语言看数据结构和算法:复杂度决定性能
c语言·数据结构·算法
刀客12342 分钟前
数据结构与算法再探(六)动态规划
算法·动态规划
金融OG1 小时前
99.11 金融难点通俗解释:净资产收益率(ROE)VS投资资本回报率(ROIC)VS总资产收益率(ROA)
大数据·python·算法·机器学习·金融
king-xxz2 小时前
动态规划:斐波那契形(初阶)
算法·动态规划
墨楠。2 小时前
数据结构学习记录-树和二叉树
数据结构·学习·算法
小唐C++2 小时前
C++小病毒-1.0勒索
开发语言·c++·vscode·python·算法·c#·编辑器
醇醛酸醚酮酯3 小时前
Leetcode热题——移动零
算法·leetcode·职场和发展
沉默的煎蛋3 小时前
MyBatis 注解开发详解
java·数据库·mysql·算法·mybatis