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
相关推荐
佳児素花痴╮1 小时前
树的基础知识与查找排序算法
数据结构·算法
lueluelue478 小时前
LeetCode:链表
算法·leetcode·链表
橘子汽水16811 小时前
Leetcode 23,543合并K个升序链表,二叉树的直径
算法·leetcode·链表
huameinan狮子11 小时前
Adaboost算法原理与计算实例
算法
别怪我很水11 小时前
API中提供了VelocityTracker类用于计算触摸事件MotionEvent的速度,而其内部默认使用的方法就是最小二乘法,本 ...
算法·gitee·最小二乘法
Re.不晚14 小时前
挑战做100道力扣算法- DAY1
算法·leetcode·职场和发展
蓝悦无人机14 小时前
《Planning algorithms》读书笔记——第1章 引言
算法·读书笔记·规划算法·lavalle
Sagittarius_A*14 小时前
分组密码基础(二):Feistel 结构与 DES 的设计思想
算法·信息安全·密码学·des·数论
青山木15 小时前
Hot 100 --- 搜索插入位置
java·数据结构·算法·leetcode