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
相关推荐
多米Domi0112 分钟前
0x3f 第21天 三更java进阶1-35 hot100普通数组
java·python·算法·leetcode·动态规划
地平线开发者3 分钟前
LLM 量化技术概述及 AWQ 和 GPTQ 介绍
算法·自动驾驶
AI科技星16 分钟前
统一场论中电场的几何起源:基于立体角变化率的第一性原理推导与验证
服务器·人工智能·线性代数·算法·矩阵·生活
Keep_Trying_Go1 小时前
基于无监督backbone无需训练的类别无关目标统计CountingDINO算法详解
人工智能·python·算法·多模态·目标统计
有时间要学习2 小时前
面试150——第三周
算法·面试
一车小面包2 小时前
Neo4j中的APOC
算法·neo4j
H_BB2 小时前
前缀和算法详解
数据结构·算法
聆风吟º2 小时前
【数据结构手札】时间复杂度详解:概念 | 大O渐进表示法 | 习题
数据结构·算法·时间复杂度·大o渐进表示法
山楂树の3 小时前
买卖股票的最佳时机(动态规划)
算法·动态规划
小O的算法实验室4 小时前
2024年IEEE TMC SCI1区TOP,面向无人机辅助 MEC 系统的轨迹规划与任务卸载的双蚁群算法,深度解析+性能实测
算法·无人机·论文复现·智能算法·智能算法改进