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. (转)注意力机制(Attention Mechanism)在自然语言处理中的应用

    注意力机制(Attention Mechanism)在自然语言处理中的应用 本文转自:http://www.cnblogs.com/robert-dlut/p/5952032.html  近年来,深度 ...

  2. 不同操作系统上屏蔽oracle的操作系统认证方式

    windows系统上>如果不想用户通过操作系统验证方式登录,可以修改 sqlnet.ora文件,把 SQLNET.AUTHENTICATION_SERVICES=NTS 前面加#注释掉就可以了. ...

  3. SSD(Single Shot MultiBox Detector)的安装配置和运行

    下文图文介绍转自watersink的博文SSD(Single Shot MultiBox Detector)不得不说的那些事. 该方法出自2016年的一篇ECCV的oral paper,SSD: Si ...

  4. Spring加载resource时classpath*:与classpath:的区别

    http://blog.csdn.net/kkdelta/article/details/5507799   classpath: 第一个匹配的 classpath*:多个组件中的可匹配的

  5. 安全快速修改Mysql数据库名的5种方法

    1. RENAME DATABASE db_name TO new_db_name这个..这个语法在mysql 5.1.7中被添加进来,到了5.1.23又去掉了.据说有可能丢失数据.还是不要用的好.详 ...

  6. js计算日期之间的月份差

    <script type="text/javascript"> getMonthBetween("2015-05-01","2016-05 ...

  7. 对char类型的理解以及对补码的理解分析

    今天遇到这样一个小程序,觉得当中有些问题很容易让人忽略的! 这个程序代码如下: 程序的结果为: 我想很多像我一样的小白可能才开始是想不明白为什么最后的结果是255吧!首先,我们得知道 strlen() ...

  8. Android学习笔记(三)

    在手机应用中菜单是很重要的一部分,它能够以直观的界面让用户去选择,现在我们学习如何去新建一个菜单. 首先在res目录下新建一个menu文件夹,然后在menu文件夹下新建一个Android XML Fi ...

  9. Discuz有关问题解决办法汇总

    1.Can not write to cache files, please check directory ./data/ and ./data/cache/ . 无法写入缓存 解决办法:在sour ...

  10. RMAN_学习笔记2_RMAN Setup配置和监控

    2014-12-23 Created By BaoXinjian