LeetCode刷题 (Python) | 274. H-Index
来源:互联网 发布:sony平板 软件 编辑:程序博客网 时间:2024/06/07 02:58
题目链接
https://leetcode.com/problems/h-index/
心得
挺有意思的题目,算H因子。
首先抽象出H因子的定义,在数组中找到一个数字H,使得数组中至少有H个数字大于等于H,其余的数学小于等于H。
分析题目中给的例子
如果数组是有序数组呢?那么对于任意一个可能的值,用
AC代码
class Solution(object): def hIndex(self, citations): """ :type citations: List[int] :rtype: int """ citations.sort(reverse=False) h = len(citations) index = 0 while index < len(citations): if citations[index] >= h: return h index += 1 h -= 1 return 0if __name__ == '__main__': s = Solution() print(s.hIndex([3, 0, 6, 1, 5]))
0 0
- LeetCode刷题 (Python) | 274. H-Index
- LeetCode刷题 (Python) | 275. H-Index II
- 【LEETCODE】274-H-Index [Python]
- [leetcode] 274.H-Index
- Leetcode 274. H-Index
- leetcode 274. H-Index
- LeetCode *** 274. H-Index
- leetcode.274. H-Index
- 【leetcode】274. H-Index
- LeetCode - 274. H-Index
- LeetCode:274. H-Index
- [leetcode] 274. H-Index
- LeetCode 274.H-Index
- LeetCode 274. H-Index
- [LeetCode]274. H-Index
- 【LeetCode】 274. H-Index
- leetcode 274. H-Index
- Leetcode 274. H-Index
- poj 1915 Knight Moves
- 1019. 数字黑洞
- spring(DI)注解的使用、类扫描的注解、Xml的继承、注解的继承
- hdu 4081 Qin Shi Huang's National Road System 秦始皇的国家公路系统
- Hduoj1285【拓扑排序】
- LeetCode刷题 (Python) | 274. H-Index
- keil为什么延时函数无效
- ...
- HDU 4725 The Shortest Path in Nya Graph(最短路)
- cvMatchTemplate() 模板匹配
- w3c盒子布局margin-right和margin-bottom无效的解决方案
- OpenFoam--有限体积-计算流体力学-开源
- 2016蓝桥杯算法训练——矩阵乘法
- Android 学习(2)