LeetCode OJ:H-Index(H指数)
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 than h 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 {
public:
int hIndex(vector<int>& citations) {
int n = citations.size();
vector<int>index(n + , );//注意这里是n+1
for(int i = ; i < n; ++i){
if(citations[i]>=n)
index[n]++;
else
index[citations[i]]++;
}
if(index[n] >= n) return n;
for(int i = citations.size()-; i >= ; --i){
index[i]+=index[i+];
if(index[i] >= i)
return i;
}
return ;
}
};
LeetCode OJ:H-Index(H指数)的更多相关文章
- [LeetCode] H-Index II 求H指数之二
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize ...
- LeetCode OJ 题解
博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...
- [LeetCode OJ] Copy List with Random Pointer 扩大
职务地址:https://oj.leetcode.com/problems/copy-list-with-random-pointer/ 题意:对一个有回路的链表的深复制 解题:这道题我AC了之后才发 ...
- LeetCode OJ 274. H-Index
Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...
- LeetCode OJ学习
一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...
- 【LeetCode OJ】Interleaving String
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...
- 【LeetCode OJ】Reverse Words in a String
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...
- LeetCode OJ 297. Serialize and Deserialize Binary Tree
Serialization is the process of converting a data structure or object into a sequence of bits so tha ...
- 备份LeetCode OJ自己编写的代码
常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...
随机推荐
- $Linux vi/vim编辑器常用命令与用法总结 (Markdown编辑版)
vi/vim是什么? Linux世界几乎所有的配置文件都是以纯文本形式存在的,而在所有的Linux发行版系统上都有vi编辑器,因此利用简单的文字编辑软件就能够轻松地修改系统的各种配置了,非常方便.vi ...
- iOS 所有设备一览 && CoreFoundation源码
1. 所有设备一览 https://en.wikipedia.org/wiki/List_of_iOS_devices 2. CoreFoundation源码(可以看看runloop.runtime的 ...
- Visual C++的DLL
动态链接库 (DLL) 是作为共享函数库的可执行文件. 动态链接提供了一种方法,使进程可以调用不属于其可执行代码的函数. 函数的可执行代码位于一个 DLL 中,该 DLL 包含一个或多个已被编译.链接 ...
- Android事件处理下(按键、触摸屏和滚动球的一些实现细节)
http://www.cnblogs.com/andtt/articles/2145563.html 对于按键事件,调用mDevices[i]->layoutMap->map进行映射.映射 ...
- JAVA学习笔记之JAVA 对象引用以及赋值
关于对象与引用之间的一些基本概念. 初学Java时,在很长一段时间里,总觉得基本概念很模糊.后来才知道,在许多Java书中,把对象和对象的引用混为一谈.可是,如果我分不清对象与对象引用, 那实在没 ...
- 枚举转SelectList扩展方法
public enum Avbc { Red=1, Blue=2, Whilt=3, Black=4 } public st ...
- 20145216史婧瑶《Java程序设计》第二次实验报告
实验二 Java面向对象程序设计 实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原则 5. 了解设计 ...
- linux系统调用是通过软中断实现的吗
软中断是利用硬件中断的概念,用软件方式进行模拟,实现宏观上的异步执行效果.很多情况下,软中断和信号有些类似,同时,软中断又是和硬中断相对应的,硬中断是外部设备对CPU的中断,软中断通常是硬中断服务程序 ...
- Jquery12 Ajax
学习要点: 1.Ajax 概述 2.load()方法 3.$.get()和$.post() 4.$.getScript()和$.getJSON() 5.$.ajax()方法 6.表单序列化 Ajax ...
- Tomcat热部署,Web工程中线程没有终止
近期项目中,用 jenkins 热部署 web工程时,发现工程中静态持有的线程(将ScheduledExecutorService定时任务存储在静态Map中),导致不定时出现数据库访问事务关闭异常,如 ...