H-Index II @python
2015-09-15 20:29
681 查看
Follow up for H-Index: What if the
========================
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
Note: If there are several possible values for
citationsarray 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
5papers in total and each of them had received
3, 0, 6, 1, 5citations respectively. Since the researcher has
3papers with at least
3citations each and the remaining two with no more than
3citations 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)
相关文章推荐
- Eclipse + Python 的安装与配置流程
- python unicode_escape
- python核心编程第5章课后题答案
- python decimal和fractions模块
- python math模块
- python核心编程第4章课后题答案(第二版75页)
- python核心编程第3章课后题答案(第二版55页)
- python核心编程第2章课后题答案(第二版36页)
- python运算优先级
- python部分运算符理解
- python基本概念——标识符
- python基本概念——字符串
- python使用基础(win10)
- python笔记之编程风格大比拼
- Python简明教程---学习笔记
- python笔记之中缀语法和管道实现
- python笔记之bisect模块
- python笔记之常用模块用法分析
- python笔记之itertools模块
- python笔记之提取网页中的超链接