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
相关推荐
handler011 分钟前
算法:查并集
开发语言·数据结构·c++·笔记·学习·算法·c
plus4s1 分钟前
3月19日(进阶10)
算法
Trouvaille ~5 分钟前
【优选算法篇】快速排序模型——从数组划分到快速选择
算法·leetcode·青少年编程·面试·蓝桥杯·快速排序·基础入门
Wect6 分钟前
LeetCode 918. 环形子数组的最大和:两种解法详解
前端·算法·typescript
圣保罗的大教堂12 分钟前
leetcode 3212. 统计 X 和 Y 频数相等的子矩阵数量 中等
leetcode
比昨天多敲两行16 分钟前
C++ Lsit
开发语言·c++·算法
我爱C编程17 分钟前
基于OMP正交匹配追踪和稀疏字典构造的杂波谱恢复算法matlab仿真
算法·matlab·omp·正交匹配追踪·稀疏字典构造·杂波谱恢复
云青黛18 分钟前
ReAct(推理与行动)框架
python·算法
im_AMBER29 分钟前
Leetcode 142 将有序数组转换为二叉搜索树 | 排序链表
算法·leetcode
码农三叔31 分钟前
(10-5-01)大模型时代的人形机器人感知:基于RoboBrain大模型的人形机器人通用智能感知系统(1)构建模型
人工智能·算法·机器人·人形机器人