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. LinkButton(按钮)

    使用$.fn.linkbutton.defaults重写默认值对象. 按钮组件使用超链接按钮创建.它使用一个普通的<a>标签进行展示.它可以同时显示一个图标和文本,或只有图标或文字.按钮的 ...

  2. Tengine新增健康检查模块

    总结 2.tengine的状态监控 Tengine的状态监控有两种 这里演示一个健康检查模块功能 配置一个status的location location /status { check_status ...

  3. hadoop streaming 编程

    概况 Hadoop Streaming 是一个工具, 代替编写Java的实现类,而利用可执行程序来完成map-reduce过程.一个最简单的程序 $HADOOP_HOME/bin/hadoop jar ...

  4. HDU 5806 NanoApe Loves Sequence Ⅱ (模拟)

    NanoApe Loves Sequence Ⅱ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5806 Description NanoApe, t ...

  5. ZOJ 3911 Prime Query(线段树)

    Prime Query Time Limit: 1 Second      Memory Limit: 196608 KB You are given a simple task. Given a s ...

  6. STM32的GPIO使用的函数剖析

    转载http://blog.csdn.net/wuwuhuizheyisheng/article/details/8239599 STM32的GPIO总结 作者:JCY 该文是自己学习了一段STM32 ...

  7. Mysql创建、删除用户

    1.新建用户 //登录MYSQL@>mysql -u root -p@>密码//创建用户mysql> insert into mysql.user(Host,User,Passwor ...

  8. 面试之BI-SQL--table转换

    题目如下: Num 1 2 4 6 7 8 10 11 13 写条SQL语句转成下表: Column1  Column2 1              2 4              4 6     ...

  9. react native 遇到的坑

    1.项目中新加入组件,应执行npm install命令 2.项目执行react-native run-android 报错,应进入android目录,执行gradlew.bat clean命令 3.L ...

  10. 使用Unity制作游戏关卡的教程(二)

    转自:http://gamerboom.com/archives/75554 作者:by Matthias Zarzecki 本文是“使用Unity制作<The Fork Of Truth> ...