H-Index II @python
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?
class Solution(object):
def hIndex(self, citations):
"""
:type citations: List[int]
:rtype: int
""" sort_c = citations[::-1]
for i in xrange(len(sort_c)):
if i>= sort_c[i]:
return i
return len(citations)
========================
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 thanh citations each."
For example, given citations = [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.
class Solution(object):
def hIndex(self, citations):
"""
:type citations: List[int]
:rtype: int
"""
if len(citations)<=0:return 0 sort_c = sorted(citations,reverse=True)
for i in xrange(len(sort_c)):
if i>=sort_c[i]:
return i
return len(citations)
H-Index II @python的更多相关文章
- [leetcode]Word Ladder II @ Python
[leetcode]Word Ladder II @ Python 原题地址:http://oj.leetcode.com/problems/word-ladder-ii/ 参考文献:http://b ...
- Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵
H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...
- Leetcode之二分法专题-275. H指数 II(H-Index II)
Leetcode之二分法专题-275. H指数 II(H-Index II) 给定一位研究者论文被引用次数的数组(被引用次数是非负整数),数组已经按照升序排列.编写一个方法,计算出研究者的 h 指数. ...
- Java实现 LeetCode 275 H指数 II
275. H指数 II 给定一位研究者论文被引用次数的数组(被引用次数是非负整数),数组已经按照升序排列.编写一个方法,计算出研究者的 h 指数. h 指数的定义: "h 代表"高 ...
- [Swift]LeetCode275. H指数 II | H-Index II
Given an array of citations sorted in ascending order (each citation is a non-negative integer) of a ...
- LeetCode Pascal's Triangle && Pascal's Triangle II Python
Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For example, given ...
- 119. Pascal's Triangle II@python
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...
- nyoj 103-A+B Problem II (python 大数相加)
103-A+B Problem II 内存限制:64MB 时间限制:3000ms 特判: No 通过数:10 提交数:45 难度:3 题目描述: I have a very simple proble ...
- [LeetCode] 275. H-Index II H指数 II
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize ...
随机推荐
- web.xml的schema文件
2.3和2.4: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLI ...
- 关于rimworld(边缘之地)
低缓的音乐 广阔的原野 丰富而不杂乱的地表 完美的殖民拓荒世界. 各种随机地形,丰富的资源.林木与矿产.随机生成的大世界给人真实世界的感觉. 动态而和谐的画面,随风摇摆的植被,跳跃的兔子,以及 ...
- doom启示录
半个小时之后,doom的最后一个字节抵达威斯康星大学,瞬间,上万名玩家涌向那台服务器,淹没了她,威斯康星大学的服务器瘫痪了,大卫的服务器崩溃了. “天哪”大卫在电话里结结巴巴地对杰伊说:“我还从没见过 ...
- 关于DIY操作系统的断更道歉
去年9月份正是开学的时候,刚开学没感觉忙.但是随着课程的深入,而且都是专业课,再加上招娉会一个接一个的来,渐渐显得力不从心.由于我对操作系统这一方面也是一知半解,以前也没有系统地学过计算机方面的东西, ...
- koa 核心源码介绍
链接来源 Request,Context,Response 在代码运行之前就已经存在的 Request和Response自身的方法会委托到Context中. Context源码片段 var dele ...
- python @修饰符的几种用法
http://www.360doc.com/content/17/0715/16/10408243_671545922.shtml http://www.cnblogs.com/Egbertbaron ...
- SWIFT中将信息保存到plist文件内
在项目中可能我们需要保存一些数据到plist文件中,以下就本人在学习过程中的笔记,不成熟的地方请指出. 可能我有一个类叫做Student import UIKit class Student: NSO ...
- Excel 设置下拉列表
1. 把列表的候选值写到一块区域, 可以说同Sheet也可以是另一个Sheet中. 2. 选中要设置的列, 选择 Data > Data Validation 3. 在Data Validati ...
- Android Studio - 安卓开发工具 打开后报错集合、修复指南
安卓开发工具错误修复 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享.心创新 ...
- 推荐六个在线生成网址二维码的API接口
现在很多大网站都有这样的一个功能,使用手机扫描一下网页上的二维码便可快速在手机上访问网站.想要实现这样的功能其实很简单,下面麦布分享几个在线生成网址二维码的API接口.都是采用http协议接口,无需下 ...