LeetCode OJ 274. H-Index
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.
就是一个快排,不过题意有点含糊,至少h citations并不一定意味着一定要有等于h citations的,并且剩下的N - h是no more than,也就是可以存在等于的情况。
void Swap(int A[], int a, int b){
int tmp = A[a];
A[a] = A[b];
A[b] = tmp;
}
int Partition(int* citations, int left, int right){
int pivot = citations[right];
;
; i < right; i++){
if(citations[i] >= pivot){
Swap(citations, i, j);
j++;
}
}
Swap(citations, j, right);
return j;
}
void Quick_Sort(int* citations, int left, int right){
int pivot_position;
if(left >= right){
return;
}
pivot_position = Partition(citations, left, right);
Quick_Sort(citations, left, pivot_position - );
Quick_Sort(citations, pivot_position + , right);
}
int hIndex(int* citations, int citationsSize) {
int i;
Quick_Sort(citations, , citationsSize - );
; i >= ; i--){
){
;
}
}
;
}
LeetCode OJ 274. H-Index的更多相关文章
- Java实现 LeetCode 274 H指数
274. H指数 给定一位研究者论文被引用次数的数组(被引用次数是非负整数).编写一个方法,计算出研究者的 h 指数. h 指数的定义: "h 代表"高引用次数"(hig ...
- LeetCode OJ 题解
博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...
- 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 ...
- LeetCode OJ 之 Maximal Square (最大的正方形)
题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...
- LeetCode OJ:Integer to Roman(转换整数到罗马字符)
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
随机推荐
- TeleportStone.lua --传送宝石
--[[作者信息: 超级炉石 (Teleport stone) 作者QQ:247321453 作者Email:247321453@qq.com 修改日期:2014-3-12 功能:除了传送,还有召唤N ...
- mesos INSTALL
$ git clone https://github.com/mesosphere/playa-mesos $ cd playa-mesos $ vagrant up --provision
- 获得图片颜色---摘自php手册
Example #1 imagecolorsforindex() 例子 ;$color_index = imagecolorat($im, $start_x, $start_y); // 使其可读$c ...
- TOMCAT如何建立两个端口或服务
近日,一个客户需要将系统放到公网上,局网测试的时候用的8080,但该端口已经被其它应用占用,但又不想更改之前的端口,于是查了下资料,以供后阅 针对客户的这个情况,只是说想增加一个端口,这时只需要去to ...
- 【freemaker】之获取xml的值
测试代码 @Test public void test09() throws Exception{ root.put("doc", NodeModel.parse(new Inpu ...
- 伯克利包过滤(Berkeley Packet Filter,BPF)语言
libpcap支持一种功能非常强大的过滤语言——“伯克利包过滤”语法.使用BPF过滤规则,你可以确定该获取和检查哪些流量,忽略哪些流量.BPF让你能够通过比较第2.3.4层协议中各个数据字段值的方法对 ...
- Codeforces 723e [图论][欧拉回路]
/* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给你一个有n个点,m条边的无向图,给每条边规定一个方向,使得这个图变成有向图,并且使得尽可能多的点入度与出度相同. 输出有多少个这样的点并且输出 ...
- 关于对inputstream流的复制
今天因为项目需要,获取到一个inputstream后,可能要多次利用它进行read的操作.由于流读过一次就不能再读了,所以得想点办法. 而InputStream对象本身不能复制,因为它没有实现Clon ...
- 初识selenium
今天尝试了一些selenium,感觉并没有想象中那么难.整理一篇笔记出来. 笔者使用的是Python+selenium.以下内容均是基于Windows系统和Python3.5.2. 首先是下载sele ...
- pyhon之对memcached及redis操作
Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站的速度.Memcached ...