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的更多相关文章

  1. Java实现 LeetCode 274 H指数

    274. H指数 给定一位研究者论文被引用次数的数组(被引用次数是非负整数).编写一个方法,计算出研究者的 h 指数. h 指数的定义: "h 代表"高引用次数"(hig ...

  2. LeetCode OJ 题解

    博客搬至blog.csgrandeur.com,cnblogs不再更新. 新的题解会更新在新博客:http://blog.csgrandeur.com/2014/01/15/LeetCode-OJ-S ...

  3. LeetCode OJ学习

    一直没有系统地学习过算法,不过算法确实是需要系统学习的.大二上学期,在导师的建议下开始学习数据结构,零零散散的一学期,有了链表.栈.队列.树.图等的概念.又看了下那几个经典的算法——贪心算法.分治算法 ...

  4. 【LeetCode OJ】Interleaving String

    Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 ...

  5. 【LeetCode OJ】Reverse Words in a String

    Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reve ...

  6. 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 ...

  7. 备份LeetCode OJ自己编写的代码

    常泡LC的朋友知道LC是不提供代码打包下载的,不像一般的OJ,可是我不备份代码就感觉不舒服- 其实我想说的是- 我自己写了抓取个人提交代码的小工具,放在GitCafe上了- 不知道大家有没有兴趣 ht ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 转载-- http接口、api接口、RPC接口、RMI、webservice、Restful等概念

     http接口.api接口.RPC接口.RMI.webservice.Restful等概念 收藏 Linux一叶 https://my.oschina.net/heavenly/blog/499661 ...

  2. Eclipse tomcat插件禁用热加载

    Eclipse中的tomcat插件默认是开户了热加载,只要是修改了java文件一保存,tomcat自动编译.加载.发布,很吃内存. 关闭方法: 打开eclipse,找到server项: 双击打开,修改 ...

  3. fiddler抓取手机数据包

    百度经验:http://jingyan.baidu.com/article/d8072ac4605905ec95cefda0.html

  4. <<精益创业>>读书笔记

    不要以严格地职能部门来组成公司,而是要以人们在各自专长的领域做出表现,组建跨部门的团队 在普通的管理中,如果无法实现目标,要么是计划不足,要么是技术不足 这点我感触比较深,以前在老东家的时间,刚开始是 ...

  5. [系统开发] Django Admin上传图片简单校验

    我的 models里有个ImageField字段,用来保存用户头像,希望通过Django Admin上传时校验头像大小,如果太大就报错,并且不保存. 网上有不少方法,有的通过第三方软件实现,有的通过自 ...

  6. 关于华为x2中的外置SDCard的使用

    一.前要 记录一下最近在开发生产过程中遇到的一个小问题.在使用x2的华为7寸平板时,由于需要大内存去录制视频,所以就使用X2自带的SDCard口,插入1个128G的SDCard卡.但是Android ...

  7. Intel汇编语言程序设计学习笔记1

    第一章 汇编器链接器:汇编器将汇编语言翻译成机器语言,链接器将单个文件合并为可执行文件 intel 80X86系列处理器的汇编语言与VAX或者motorala 68x00等系统的汇编是否相同?不相同, ...

  8. JavaScript笔记基础篇(一)

    一. 常用正则表达式汇总以及部分问题解决方案 正则匹配: var str = "This is my test"; var test = new RegExp("test ...

  9. ZeroClipboard实现复制

    今天利用ZeroClipboard实现了批量复制ip到剪贴版的公里,第一种方式总是有错,需要点击两次才能成功复制,第二种方法成功.在这里记录下,方法一: $('#copy_ips').zclip({ ...

  10. lua 基础库

    数学库: 三角函数:math.sin, math.cos, math.tan, math.asin, math.acos 都以弧度为单位: 指数和对数函数:exp, log, log10: 取整函数: ...