LeetCode: 275. H-Index II

【目录】专栏文章导航 从最强工具链Davinci Configurator模块学习出发掌握AUTOSAR 阅读详情

LeetCode: 275. H-Index II

题目描述

Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.

According to the definition of h-index on Wikipedia: “A scientist has index h if h of his/her N papers have at least h citations each, and the other N − h papers have no more than h citations each.”

Example:

Input: citations = [0,1,3,5,6]
Output: 3 
Explanation: [0,1,3,5,6] means the researcher has 5 papers in total and each of them had 
             received 0, 1, 3, 5, 6 citations respectively. 
             Since the researcher has 3 papers with at least 3 citations each and the remaining 
             two with no more than 3 citations each, her h-index is 3.

Note:

  • If there are several possible values for h, the maximum one is taken as the h-index.

Follow up:

  • This is a follow up problem to H-Index, where citations is now guaranteed to be sorted in ascending order.
    Could you solve it in logarithmic time complexity?

解题思路 —— 二分查找

  • citations[mid] >= citations.size()-mid: 尝试在 ‘[left, mid)’ 寻找使得 h 更大的 mid
  • 否则, 尝试在 ‘[mid, right)’ 寻找符合题意的 mid

AC 代码

class Solution 
{
public:
    int hIndex(vector<int>& citations) 
    {
        int left = 0, right = citations.size();
        while(left < right)
        {
            int mid = (left+right)/2;
            if(citations[mid] >= citations.size()-mid)
            {
                // [left, mid)
                right = mid;
            }
            else
            {
                // [mid+1, right)
                left = mid + 1;
            }
        }
        
        return citations.size()-left;
    }
};
Statistics and Machine Learning Toolbox Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具 立即下载

相关推荐

手把手教你为RV1126开发板点亮3寸MIPI屏(ST7701S驱动,含设备树配置避坑点)

本文详细介绍了RV1126开发板适配3寸MIPI屏幕(ST7701S驱动)的全流程,涵盖硬件设计、信号完整性保障、屏幕时序参数计算及设备树配置等关键步骤。特别针对MIPI差分信号布线、电压匹配和设备树配置中的常见问题提供了实用解决方案,帮助开发者高效完成屏幕适配工作。

weixin_42524703的博客 345

leetcode 275: H-Index II

Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? [思路] 二分查找, [CODE] public class Solution { public int hIndex(int[]

西施豆腐渣 3327

Hi3516CV610硬件设计避坑指南:从电源模块到DDR布线实战解析

本文深入解析了Hi3516CV610硬件设计中的关键难点与实战技巧。重点剖析了电源架构的选型陷阱与PCB布局要点,详细阐述了DDR3/L高速布线的等长匹配、信号完整性及端接策略,并提供了MIPI接口与时钟电路的隔离设计指南。旨在帮助工程师规避常见设计错误,提升系统稳定性与可靠性。

ooo22的博客 262

LeetCode 275: H-Index II

275. H-Index IIDifficulty: Medium Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?Hint: Expected runtime complexity is in O(log n) a

Cycle1413的博客 469

Skynet 框架面试题

本文整理了游戏服务端开发面试中 Skynet 框架的高频考点,涵盖底层架构、消息派发、协程调度、网络 I/O、harbor 跨机通信、内存管理、socket 处理、阻塞操作、错误处理等核心内容。全面覆盖 Skynet 框架的原理、使用和实战问题,追求深入准确,拒绝八股文。

小赖的博客 391

Android Binder的两三事--基于Android14源码

Android14-Framework-Binder

保持专注,保持热爱 1146

Leetcode 275: H-Index II

Follow upforH-Index: What if thecitationsarray is sorted in ascending order? Could you optimize your algorithm? 1 public class Solution { 2 public int HIndex(int[] citations) { 3 ...

weixin_30300523的博客 121

【2025最新版】Open3D 区域生长分割(python详细过程版)

点云区域生长分割算法的python详细过程版实现。博客长期更新,本文最新更新时间为:2025年3月23日。

点云侠的博客 9533

Leetcode 275 : H-Index II

Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm? 思路:参考H-Index的思路,只是这次不需要再进行排序操作了,复杂度为O(n),代码如下: public int hIndex(int[] citat

a530552571的专栏 351

ctle电路求帮忙分析低中高频调节原理,搭好了电路该怎样调节参数?

🏆本文收录于专栏,主要记录项目实战过程中所遇到的Bug或因后果及提供真实有效的解决方案,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家!持续更新中,up!up!up!!

**My Coding Family** 1136

Microsemi Libero系列教程(四)——PLL的使用

文章目录PLL是什么Libero中PLL的使用官方文档 系列教程:Microsemi Libero系列教程 PLL是什么 PLL(Phase Locked Loop): 为锁相回路或锁相环,用来统一整合时钟信号,使高频器件正常工作,如内存的存取资料等。PLL用于振荡器中的反馈技术。 许多电子设备要正常工作,通常需要外部的输入信号与内部的振荡信号同步。一般的晶振由于工艺与成本原因,做不到很高的频率...

whik1194的博客 7224

LeetCode:274. H-Index & 275. H-Index II

这一题算是第一次写桶排序,然后自己又没有看出来可以用二分法。 二分法真的很重要,只要可以用,基本就是最优的方法。符合之前总结的规律就可以用。大多数情况下不是一眼就能够看出来,所以需要时刻提醒一下自己,是不是可以用二分法来做。 首先是自己的做法: class Solution { public: int hIndex(vector<int>& citations) {...

weixin_43462819的博客 159

红队内网攻防渗透:内网渗透之内网对抗:实战项目&VPC1打靶&PHP-RCE&三层代理路由&防火墙上线&密码喷射&域控提权

上面已经抓取到了密码,但是我们通过拓扑分析看,要想上线win10只能通过正向shell,因为win7的防火墙是开的,win10反向主动连接肯定入站规则拦截,而win10自己没有开防火墙,所以win7主动正向连接就可以上线。win7开启了防火墙,入站规则肯定是会拦截我们的请求的,所以我们需要反向上线,让win7主动来连接我们。这里扫描发现是存在ms17010漏洞的,但是想上线192.168.2.142的话,我们没有路由是上线不了的,这里有两种办法:一种msf直接生成后门,另一种cs移植后门到msf。

HACKONE的博客 917

【二分法】- leetcode

275. H-Index II 278. First Bad Version 此题的条件必须是left < right, 否则如果只有一个版本的话,一直跳不出循环, time limitation。 转载于:https://www.cnblogs.com/93scarlett/p/6353765.html...

weixin_30240349的博客 94

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

leetcode笔记 - 275.H指数II (H-Index II)

Leetcode 275. H-Index II 没想到这个题也可以用二分法做,真是惊喜,可能自己做的题还不够,一时没想到用二分法,就感觉很有意思 哈哈哈 我的第一想法 有顺序嘛,那就从开头一直向后找 哈哈哈 暴力,咦 难怪最近看新闻报道某厂 男 暴力女友,哎 算法题做多了呗,算法不提倡暴力,生活也不提倡哈 生活不易 请有缘人互相珍惜呀。 class Solution { public int hIndex(int[] citations) { int i = 0;

weixin_44290410的博客 252

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

【Leetcode】275. H-Index II

题目地址: https://leetcode.com/problems/h-index-ii/ 题意是,给定一个单调增非负数组,找出满足这样性质的数hhh:有多于等于hhh个数是大于等于hhh的。返回满足这样条件的最大的那个hhh。 思路是二分。首先考虑解的范围。显然000是满足条件的,并且hhh最大不超过数组长度nnn,否则的话,要存在多于n+1n+1n+1个大于等于n+1n+1n+1的数,超出...

数学、算法爱好者的博客 266

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

leetcode 274, 275. H-Index I, II(H 指数问题合集,线性查找/二分查找)

274. H-Index https://leetcode.com/problems/h-index/ 题解 第一遍没看懂题目。看了中文版的题目才明白,是要找到 h,满足总共有 h 篇论文分别被引用了至少 h 次。 经过观察发现,数组排序后,所谓“至少被引用了 h 次”,就是数组中大于等于 h 的数字的个数,也就是排序数组中 h 位置右边的数字个数。 所以思路是,先对数组排序,排序后,反向下标遍历数组,当下标首次 大于或等于 数组的值时,返回。其中: 等于,则返回 i 大于,则返回 i-1 代码 c

寒泉 5万+

LeetCode 275. H-Index II

分析 难度 中 来源 https://leetcode.com/problems/h-index-ii/ 题目 Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a researcher, write a function to compute the...

ov流岚vo的专栏 294

LeetCode 275. H-Index II(二分查找)

275. H-Index II Medium Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index. According ...

da_kao_la的博客 272

leetcode 275. H-Index II-h因子|二分查找

原题链接:275. H-Index II 【思路-Java、Python】 二分查找 T=O(logn)|M=O(1) 本题是基于 leetcode 274. H-Index-h因子|哈希表,如果对于 h-index 概念不是很理解的可以参考这篇博文。 本题采用二分查找进行 public class Solution { public int hIndex(int[] citati

hdtopku 2272

[leetcode] 275. H-Index II

Description Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index. According to the defi...

Learning from the mistakes 195

leetcode 275.h指数-ii(h index ii)C语言

leetcode 275.h指数-ii(h index ii)C语言1.description2.solution 1.description https://leetcode-cn.com/problems/h-index-ii/description/ 给定一位研究者论文被引用次数的数组(被引用次数是非负整数),数组已经按照升序排列。编写一个方法,计算出研究者的 h 指数。 h 指数的定义: “h 代表“高引用次数”(high citations),一名科研人员的 h 指数是指他(她)的 (N 篇论文中

hsk6543210的博客 443

(Java) LeetCode 275. H-Index II —— H指数 II

Given an array of citationssortedin ascending order(each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index. According to thedefinition...

anzeng0652的博客 396

LeetCode //C - 275. H-Index II

【代码】LeetCode //C - 275. H-Index II。

Made in Code 747

leetcode - 275. H-Index II

leetcode - 275

sinat_41679123的博客 1105

274. H-Index && 275. H-Index II

274题目:https://leetcode.com/problems/h-index/ 275题目:https://leetcode.com/problems/h-index-ii/ (275是274的简化版,已经排好序了) 思路 排序,h的值可能是【0,N】中的任意值,排序之后能清楚的了解当取h=【0,N】过程中是否满足条件 特判返回0的情况 从N-1遍历到1,先满足h条件的跳...

快乐划水程序猿的专栏 249
上一篇: LeetCode: 274. H-Index
下一篇: LeetCode: 278. First Bad Version
IT技术小密圈
博客等级 码龄12年 1385粉丝 322原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值