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 ...
随机推荐
- ExceptionHandler 异常公共处理
异常的公共处理很多种,采用注解的方式,拦截器的方式等都可以,我采用的是继承 AbstractHandlerExceptionResolver 来实现, 上代码 package com.yun.util ...
- nginx对上传文件大小的限制
前几天项目组的一个小伙子过来跟我说,他本地上传的文件没问题,但是在测试环境上测试的时候上传失败. 后来发现时nginx对上传文件的大小做了限制,默认是1M,那么按照需求我们更改了限值为20M vi c ...
- pl/sql中误删表中数据并提交恢复办法
最近在操作表中数据时,删除了表中数据,但是又想恢复,后来查到了官方的一篇文档,发现还蛮有用的,如下: 在pl/sql中运行,select * from A as of TIMESTAMP to_tim ...
- Java Junit 基础笔记
Junit 1. 概念 JUnit是一个Java语言的单元测试框架. 单元测试:单元测试(英语:Unit Testing)又称为模块测试, 是针对程序模块(软件设计的最小单位)来进行正确性检验的测试工 ...
- HDU 2907
http://acm.hdu.edu.cn/showproblem.php?pid=2907 ans=(凸包顶点数-凸包凹面数量)*q-凸包凹面数量*p 重点在求一个凸包的凹面数量,极角排序过后,当前 ...
- 安装SharePoint Server的主机重命名
今天我头脑一热, 把安装在WS 2008 R2上的有Stand-alone SharePoint Server 2010的机器重命名了一下, 结果SharePoint Central Admin都进不 ...
- valgrind- 内存泄漏-how to install and use
1.how to install my host computer is ARM, U need to Attention yours... valgrind下载: http://valgrind.o ...
- Passing the Message 单调栈两次
What a sunny day! Let’s go picnic and have barbecue! Today, all kids in “Sun Flower” kindergarten ar ...
- javascript : location 对象
window.location: window的location对象 window.location.href 整个URl字符串(在浏览器中就是完整的地址栏) window.location.prot ...
- hdu1233 还是畅通工程 最小生成树
给出修建边的边权,求连通所有点的最小花费 最小生成树裸题 #include<stdio.h> #include<string.h> #include<algorithm& ...