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
相关推荐
啊阿狸不会拉杆2 小时前
《数字图像处理》第 5 章-图像复原与重建
图像处理·人工智能·算法·matlab·数字图像处理
断剑zou天涯2 小时前
【算法笔记】资源限制类题目的解题套路
笔记·算法·哈希算法
YoungHong19922 小时前
面试经典150题[074]:填充每个节点的下一个右侧节点指针 II(LeetCode 117)
leetcode·面试·职场和发展
DanyHope2 小时前
LeetCode 128. 最长连续序列:O (n) 时间的哈希集合 + 剪枝解法全解析
前端·leetcode·哈希算法·剪枝
元亓亓亓2 小时前
LeetCode热题100--763. 划分字母区间--中等
算法·leetcode·职场和发展
Dream it possible!2 小时前
LeetCode 面试经典 150_回溯_全排列(100_46_C++_中等)
c++·leetcode·面试·回溯
鹿角片ljp2 小时前
力扣206.反转链表-双指针法(推荐)
算法·leetcode·链表
智航GIS2 小时前
ArcGIS大师之路500技---037普通克里金VS泛克里金
人工智能·算法·arcgis
晨晖23 小时前
循环队列:出队
算法
LYFlied3 小时前
【每日算法】LeetCode 70. 爬楼梯:从递归到动态规划的思维演进
算法·leetcode·面试·职场和发展·动态规划