题目:
Given an array of citations (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.”

For example, given citatio**ns = [3, 0, 6, 1, 5], which means the researcher has **5 papers in total and each of them had received 3, 0, 6, 1, 5 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, his h-index is 3.

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

思路:
就是要找一个作者写的文章的H-Index,h就是所有文章中有h篇的引用大于等于h,且剩下的文章引用都不超过h,并返回所有满足条件的h的最大值。

代码:

class Solution {
public:int hIndex(vector<int>& citations) {int len=citations.size();//先求citations的长度sort(citations.begin(),citations.end());//排序 int max=0;//max初始化为0for(int i=len-1;i>=0;--i){//从后往前遍历if(citations[i]>=len-i){//如果索引i对应的值大于len-imax = len - i > max ? len - i : max;//更新max为len-i和max中的较大值}}return max;}
};

输出结果: 3ms

LeetCode 274. H-Index相关推荐

  1. LeetCode 274. H指数(排序,哈希)

    1. 题目 给定一位研究者论文被引用次数的数组(被引用次数是非负整数).编写一个方法,计算出研究者的 h 指数. h 指数的定义: "h 代表"高引用次数"(high c ...

  2. 二分答案——H指数(Leetcode 274)

    题目选自Leetcode 274. H指数 二分查找(答案)的简单题~ 理解题意 这个例子有点儿特殊,论文被引用了 3 次,篇数有 3 篇.再来看一个更一般的例子: 结论: 这条分割线越靠左边,说明被 ...

  3. LeetCode 981. 基于时间的键值存储 / 274. H 指数 / 275. H 指数 II

    981. 基于时间的键值存储 2021.7.10 每日一题 题目描述 创建一个基于时间的键值存储类 TimeMap,它支持下面两个操作:1. set(string key, string value, ...

  4. LeetCode Algorithm 274. H 指数

    274. H 指数 Ideas H指数表示的是有h篇论文被引用了至少h次. 我们可以将citations逆序排列,表示引用次数从高到底排列. 如果我们从前向后遍历数组,那么第i位上值v,就表示至少有i ...

  5. LeetCode 275. H指数 II(二分查找)

    1. 题目 给定一位研究者论文被引用次数的数组(被引用次数是非负整数),数组已经按照升序排列.编写一个方法,计算出研究者的 h 指数. h 指数的定义: "h 代表"高引用次数&q ...

  6. LeetCode 852. Peak Index in a Mountain Array

    LeetCode 852. Peak Index in a Mountain Array Solution1:我的答案 时间复杂度O(n)O(n)O(n) class Solution { publi ...

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

    274. H-Index https://leetcode.com/problems/h-index/ 题解 第一遍没看懂题目.看了中文版的题目才明白,是要找到 h,满足总共有 h 篇论文分别被引用了 ...

  8. 274. H 指数----中等

    题目 给定一位研究者论文被引用次数的数组(被引用次数是非负整数).编写一个方法,计算出研究者的 h 指数. h 指数的定义:h 代表"高引用次数"(high citations), ...

  9. LeetCode Random Pick Index(蓄水池抽样算法)

    问题:给出一个数组,存在相同的数,随机输出目标数所在的下标 思路:使用蓄水池抽样算法,当第一次找到目标数时,作为选取.接着如果随机数等于0,则选取.在遍历完后,直接返回选取的值 具体代码参考: htt ...

最新文章

  1. 逻辑 STANDBY ORA-00368日志应用失败处理一例
  2. ENGINEER 003:配置IPv6地址
  3. PAT甲级1073 Scientific Notation:[C++题解]字符串处理、科学计数法
  4. 临床研究数据分析的6种常用方法
  5. python 命名管道_Python:检查命名管道是否有数据
  6. FCN学习:Semantic Segmentation
  7. python怎么安装bokeh_python怎么安装bokeh
  8. PTA c语言 统计一行文本的单词个数
  9. Dubbo与Spring Cloud
  10. python编写一个简单的程序验证码_针对验证码,做一个简单的自动网上签到程序(一)...
  11. 微信公众号自定义消息模板(处理数据)
  12. Java之BIO网络编程
  13. java流重定向如何分类,Java 文件流与标准流之间的重定向
  14. 测试工程师如何提高工作效率
  15. 苹果微信换行怎么打_微信朋友圈发长文被折叠成一行怎么破?附苹果安卓解决方案...
  16. 园区网络—中小型企业网络工程项目实践(思科模拟器)
  17. Java基础面试题精选汇总,备战面试突破篇--直击offer
  18. Google Map开发之实战
  19. 51单片机——定时器的原理和使用
  20. 2021-10-18血压计方案|血压计模块

热门文章

  1. java wait 参数_java中wait()和join()方法的区别是什么
  2. python爬取网页上的特定链接_自学python爬虫二:如何正常操作urllib2通过指定的URL抓取网页内容...
  3. linux ioctl及ioctl command
  4. opencv空间色彩转换
  5. python numpy ndarray之basic operations
  6. int转为string类型方法
  7. 百度统计:网站统计实时访客报告
  8. 代码注释: (文字图案:HIRE)
  9. 流量卡官网源码多功能集成式源码
  10. jtag接口原理图_在开始高速接口前,我们来试试IBERT测试吧!