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 ...
随机推荐
- 基于MVC4+EasyUI的Web开发框架形成之旅--基类控制器CRUD的操作
在上一篇随笔中,我对Web开发框架的总体界面进行了介绍,其中并提到了我的<Web开发框架>的控制器的设计关系,Web开发框架沿用了我的<Winform开发框架>的很多架构设计思 ...
- 数据库之mysql存储程序
什么时候会用到存储过程 1.存储过程只在创造时进行编译,以后每次执行存储过程都不需再重新编译,而一般 SQL 语句每执行一次就编译一次,所以使用存储过程可提高数据库执行速度2.当对数据库进行复杂操作时 ...
- Dockerfile指令
指令的一般格式为INSTRUCTION arguments,指令包括FROM.MAINTAINER.RUN等. FROM 格式为FROM <image>或FROM <image> ...
- 02 Linux 下安装JDK并测试开发“Hello World!”
测试环境 主机系统:Win7 64位 虚拟机:VMware® Workstation 11.1.0 虚拟机系统:CentOS 6.5 64位 Kernel 2.6.32-431.e16.x86_6 ...
- Perl 随笔
1. .pl 文件带入参数: ./auto_cfg.pl ./mconfig.config ./boardconfig.config ./menuconfig.config .ver ./a ...
- 移动端line-height失效
移动端高度过小,使用rem布局时div里面的文字不能用line-height垂直居中: 解决方案,先高度,字体大小扩大n倍,然后利用transform:scale(0.n)缩小即可.
- [Tex学习]WinEdit 常用软件快捷键
WinEdit 常用软件快捷键 编辑: Alt+C:在剪贴板原有复制文本后增加新的被选择的文本. Ctrl+Shift+Alt+Right/Left:对选中文本增加或者删除Comment标记. Ctr ...
- PHP中去除字符串中的换行的方法
在PHP中,有时候我们需要对字符串的换行进行过滤,比如天涯PHP博客中文章页面的description信息,我是直接截取的文章内容,并过滤掉html符号,最终还要过滤掉其中的换行.下面整理一下常见的去 ...
- img会在特定的情况下主动的第二次调用MVC的action
当img的src为空,或者不是合法路径的时候,会连续调用MVC的action两次,第二次所传的值为src的值,这常常会导致程序报错. 这不是MVC的issue,而是浏览器的行为,当response f ...
- winform下自绘提示框风格窗体
昨天分享了一个环形滚动条控件,今天分享一个提示框风格的窗体.代码如下: /// <summary> /// 继承自Form,但将FormBorderStyle设置为None /// < ...