作者: 负雪明烛
id: fuxuemingzhu
个人博客: http://fuxuemingzhu.cn/


题目地址: https://leetcode.com/problems/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 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?

题目大意

计算某个研究人员的影响因子。影响因子的计算方式是有h篇影响力至少为h的论文。影响因子是衡量作者生产力和影响力的方式,判断了他又多少篇影响力很大的论文。和274. H-Index不同的是,这个题已经排好了序。

解题方法

解释一下样例:[0,1,3,5,6],当h=0时表示至少有0篇影响力为0的论文;当h=1时表示至少有1篇影响力为1的论文;当h=3时表示至少有3篇影响力为3的论文;当h=5时表示至少有5篇影响力为5的论文;当h=6时表示至少有6篇影响力为6的论文.显然符合要求的是只要有3篇影响力为3的论文。

在274. H-Index中,是先排序再遍历做的,这个题已经排好了序,所以比274更简单,使用二分查找可以快速求解。

我们求的结果就是求影响力x和不小于该影响力的论文个数的最小值,然后再求这个最小值的最大值。

时间复杂度是O(logN),空间复杂度是O(N)。

class Solution(object):def hIndex(self, citations):""":type citations: List[int]:rtype: int"""N = len(citations)l, r = 0, N - 1H = 0while l <= r:mid = l + (r - l) / 2H = max(H, min(citations[mid], N - mid))if citations[mid] < N - mid:l = mid + 1else:r = mid - 1return H

参考资料:

日期

2018 年 10 月 6 日 —— 努力看书

【LeetCode】275. H-Index II 解题报告(Python)相关推荐

  1. LeetCode 167.Two Sum II 解题报告

    LeetCode 167.Two Sum II 解题报告 题目描述 Given an array of integers that is already sorted in ascending ord ...

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

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

  3. leetcode 275. H 指数 II

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

  4. 【LeetCode】517. 超级洗衣机 解题报告 (python)

    原题地址:https://leetcode-cn.com/problems/super-washing-machines/submissions/ 题目描述: 假设有 n 台超级洗衣机放在同一排上.开 ...

  5. [leetcode] 213. House Robber II 解题报告

    题目链接:https://leetcode.com/problems/house-robber-ii/ Note: This is an extension of House Robber. Afte ...

  6. [Leetcode] 212. Word Search II 解题报告

    题目: Given a 2D board and a list of words from the dictionary, find all words in the board. Each word ...

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

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

  8. 【LeetCode】91. Decode Ways 解题报告(Python)

    [LeetCode]91. Decode Ways 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...

  9. [LeetCode]844. Backspace String Compare 解题报告(C++)

    [LeetCode]844. Backspace String Compare 解题报告(C++) 题目描述 Given two strings S and T, return if they are ...

最新文章

  1. 11matlab [A rank]=sort (B), P = p(rank,: )的问题 and ~符号运算
  2. 分布式、服务化的ERP系统架构设计
  3. HTML5在豆瓣的各种应用
  4. Ubuntu 16.04下减小/释放/清理VirtualBox虚拟硬盘文件的大小
  5. 32f407tim4时钟源频率_STM32学习笔记04—SysTick时钟
  6. python global用法_【python测试开发栈】python基础语法大盘点
  7. ELK+Kafka集群日志分析系统
  8. mysql基础语法(常用)
  9. Flex Socket 安全沙箱问题解决
  10. 跟进table_cache参数
  11. 统一返回的json时间格式
  12. DCASE三次挑战赛概览
  13. c语言int超出范围字符串,Go返回int64类型字段超出javascript Number范围的解决方法...
  14. c++和python有联系吗_Python和C++交互
  15. 沟通艺术-善于揣摩对方心思,才能把话说到心坎上
  16. 电脑如何测网速_【网络调试】网络速度检测工具有哪些?这五款工具让你随时掌控网速...
  17. MSSQL中Case语句的用法
  18. 应用安全 - Web安全 - 文件包含攻防
  19. Oracle SqlLoader使用
  20. x线计算机体层成像设备教案,医学影像设备学第4章-数字X线设备ppt课件

热门文章

  1. 你听说过「互联网档案馆」吗?
  2. 3天怒肝5万字!阿里P7大佬手写MySQL超全笔记,还担心学不会吗?
  3. 苹果打击刷排名背后:国内Top100应用10%刷榜
  4. Qt 中获取字体的像素高度和宽度
  5. python中time是什么意思_python3时间中time是什么?怎么转换?
  6. 基于Python3爬取并下载网易云歌曲!
  7. 安卓一键清理内存_力推!一键深度清理手机内存垃圾,从此和卡顿告别
  8. JAVA计算机毕业设计宠物领养饲养交流管理平台Mybatis+系统+数据库+调试部署
  9. 26岁开始学iT晚吗?
  10. 关于职业规划,尤其值得我们程序员学习、思考