Leetcode 275. H-Index II

Problem

Given an array of integers citations where citationsi 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
相关推荐
一个儒雅随和的男子15 小时前
限流算法详细剖析
java·服务器·算法
工业胶粘剂技术16 小时前
单组分高温环氧结构胶 K-EP280 完整技术参数与工程选型分析
算法·制造
小欣加油16 小时前
Leetcode31 下一个排列
数据结构·c++·算法·leetcode·职场和发展
_日拱一卒17 小时前
LeetCode:39组合总和
java·算法·leetcode·职场和发展
无限进步_17 小时前
【Linux】进程状态、僵尸与孤儿、进程调度
linux·运维·服务器·开发语言·数据结构·算法
郝学胜-神的一滴17 小时前
力扣 662 :二叉树最大宽度
java·数据结构·c++·python·算法·leetcode·职场和发展
2301_7644413317 小时前
基于Stackelberg博弈的分散式库存模型
python·算法·数学建模
qq 137401861117 小时前
医用无菌屏障系统加速老化标准解读:ASTM F1980-2016 全解析
人工智能·算法·加速老化·包装测试·astm·医疗器械包装·无菌屏障系统
wayz1117 小时前
Overlap:SLOPE(线性回归斜率)技术指标详解
算法·金融·数据分析·回归·线性回归·量化交易·特征工程
点云兔子17 小时前
舱口检测:从点云到矩形定位的射线投影算法
opencv·算法·点云·舱口检测