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.

Hint:

An easy approach is to sort the array first.
What are the possible values of h-index?
A faster approach is to use extra space.

 /*************************************************************************
> File Name: LeetCode274.c
> Author: Juntaran
> Mail: JuntaranMail@gmail.com
> Created Time: Thu 19 May 2016 20:47:36 PM CST
************************************************************************/ /************************************************************************* 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. Hint: An easy approach is to sort the array first.
What are the possible values of h-index?
A faster approach is to use extra space. ************************************************************************/ #include "stdio.h" void quick_sort( int* nums, int left, int right )
{
if( left < right )
{
int i = left;
int j = right;
int flag = nums[left]; while( i < j )
{
while( i<j && nums[j]>=flag ) // 从右向左找第一个小于x的数
{
j--;
}
if( i < j )
{
nums[i++] = nums[j];
} while( i<j && nums[i]<flag ) // 从左向右找第一个大于等于x的数
{
i++;
}
if( i < j )
{
nums[j--] = nums[i];
}
}
nums[i] = flag;
quick_sort( nums, left, i- );
quick_sort( nums, i+, right);
}
} void printfNums( int* nums, int numsSize )
{
int i;
for( i=; i<numsSize; i++ )
{
printf("%d ", nums[i]);
}
printf("\n");
} int hIndex(int* citations, int citationsSize)
{ quick_sort( citations, , citationsSize- ); int i;
for( i=; i<citationsSize; i++ )
{
if( (citationsSize-i) <= citations[i] )
{
return citationsSize-i;
}
}
return ;
} int main()
{
int citations[] = {,,,,,,,,};
int citationsSize = ;
int left = ;
int right = ; printfNums( citations, citationsSize );
quick_sort( citations, left, right );
printfNums( citations, citationsSize ); int ret = hIndex( citations, citationsSize );
printf("%d\n", ret); return ;
}

LeetCode 274的更多相关文章

  1. leetcode@ [274/275] H-Index & H-Index II (Binary Search & Array)

    https://leetcode.com/problems/h-index/ Given an array of citations (each citation is a non-negative ...

  2. [LeetCode] 274. H-Index H指数

    Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...

  3. Java实现 LeetCode 274 H指数

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

  4. [LeetCode#274]H-Index

    Problem: Given an array of citations (each citation is a non-negative integer) of a researcher, writ ...

  5. Leetcode 274.H指数

    H指数 给定一位研究者论文被引用次数的数组(被引用次数是非负整数).编写一个方法,计算出研究者的 h 指数. h 指数的定义: "一位有 h 指数的学者,代表他(她)的 N 篇论文中至多有 ...

  6. leetcode & lintcode for bug-free

    刷题备忘录,for bug-free leetcode 396. Rotate Function 题意: Given an array of integers A and let n to be it ...

  7. leetcode & lintcode 题解

    刷题备忘录,for bug-free 招行面试题--求无序数组最长连续序列的长度,这里连续指的是值连续--间隔为1,并不是数值的位置连续 问题: 给出一个未排序的整数数组,找出最长的连续元素序列的长度 ...

  8. [LeetCode] 275. H-Index II H指数 II

    Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize ...

  9. 【LeetCode】274. H-Index 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/h-index/ ...

随机推荐

  1. Linux里实用命令之添加行号、文本和语法高亮显示

    写在前面的话 本博主我,强烈建议,来看此博文的朋友们,都玩玩. 最好,在刚入门的时候呢,不加行号,不玩文本和语法高亮显示,以后会深有体会.磨炼自己! 步骤一:进入 /etc/virc配置文件 步骤二: ...

  2. Java缓存学习之二:浏览器缓存机制

    浏览器端的九种缓存机制介绍 浏览器缓存是浏览器端保存数据用于快速读取或避免重复资源请求的优化机制,有效的缓存使用可以避免重复的网络请求和浏览器快速地读取本地数据,整体上加速网页展示给用户.浏览器端缓存 ...

  3. HTML+CSS+JS学习总结

    HTML: 什么是 HTML? HTML 是用来描述网页的一种语言. HTML 指的是超文本标记语言 (Hyper Text Markup Language) HTML 不是一种编程语言,而是一种标记 ...

  4. Linux性能监测

    1.Linux性能监测:监测目的与工具介绍 看了某某教程.读了某某手册,按照要求改改某些设置.系统设定.内核参数就认为做到系统优化的想法很傻很天真:)系统优化是一项复杂.繁琐.长期的工作,优化前需要监 ...

  5. Qt 自动搜索串口号列表

    @功能: SerialPortList 类实现当前可用的串口进行实时扫描,当发现有新的串口 或是现有串口消失时,SerialPortList类将发出一个QStringList类型的 信号onNewSe ...

  6. [支付]微信NATIVE扫码支付JAVA实现

    步骤: 1.预订单 2.接受微信返回的url 3.将url转为二维码显示到页面上 4.扫码支付 5.接收微信的异步通知,在这步修改订单的状态 6.收到异步通知的同时给微信返回指定数据,告知对方已成功处 ...

  7. jq简单选项卡

    function tabControl(obj,elm){ $(obj).hover(function(){ $(this).addClass('active').siblings().removeC ...

  8. Tiny6410声卡驱动——录音与回放

    在Linux下,音频设备程序的实现与文件系统的操作密切相关.Linux将各种设备以文件的形式给出统一的接口,这样的设计使得对设备的编程与对文件的操作基本相同,对Linux内核的系统调用也基本一致,从而 ...

  9. 数据库存取缓冲区的LRU与MRU算法

    数据库存取缓冲区的LRU与MRU算法 1.Cache Hit and Cache Miss 当使用者第一次向数据库发出查询数据的请求的时候,数据库会先在缓冲区中查找该数据,如果要访问的数据恰好已经在缓 ...

  10. python的一些总结1

    1.安装环境 window用户下载 python :https://www.python.org/downloads/release/python-2710/ 安装不解释.. 配置环境变量  找到 P ...