LeetCode 274

时间:2022-11-12 14:20:48

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&commat; &lbrack;274&sol;275&rsqb; H-Index &amp&semi; H-Index II &lpar;Binary Search &amp&semi; Array&rpar;

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

  2. &lbrack;LeetCode&rsqb; 274&period; 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. &lbrack;LeetCode&num;274&rsqb;H-Index

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

  5. Leetcode 274&period;H指数

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

  6. leetcode &amp&semi; 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 &amp&semi; lintcode 题解

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

  8. &lbrack;LeetCode&rsqb; 275&period; 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&period; H-Index 解题报告(Python)

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

随机推荐

  1. 聊聊ASP&period;NET Core默认提供的这个跨平台的服务器&mdash&semi;&mdash&semi;KestrelServer

    跨平台是ASP.NET Core一个显著的特性,而KestrelServer是目前微软推出了唯一一个能够真正跨平台的Server.KestrelServer利用一个名为KestrelEngine的网络 ...

  2. 实现TableLayout布局下循环取出TableRow控件中的文字内容到list集合

    布局方式为TableLayout,利于实现表单样式展现. <!-- 详情内容区域 --> <ScrollView android:layout_above="@id/id_ ...

  3. jsf2入门视频 教程

    jsf2.0 入门视频 教程   需要的看下.初次录视频.还有很多需要完善. JSF交流QQ群84376982 JSF入门视频下载地址  http://pan.baidu.com/s/1jG3y4T4 ...

  4. &lbrack;Data Structure&rsqb; 二叉搜索树&lpar;Binary Search Tree&rpar; - 笔记

    1. 二叉搜索树,可以用作字典,或者优先队列. 2. 根节点 root 是树结构里面唯一一个其父节点为空的节点. 3. 二叉树搜索树的属性: 假设 x 是二叉搜索树的一个节点.如果 y 是 x 左子树 ...

  5. Spring Boot启动过程(四):Spring Boot内嵌Tomcat启动

    之前在Spring Boot启动过程(二)提到过createEmbeddedServletContainer创建了内嵌的Servlet容器,我用的是默认的Tomcat. private void cr ...

  6. 模拟开户接口,使用python脚本实现批量用户开通

    1.目的 通过模拟接口方法,实现批量用户开通 2.分析 A.接口含body和head部分,其中body中的某些变量为必填字段,包含用户的信息. B.用户信息清单可以整理成ott_after_check ...

  7. ASP&period;NETZERO 开发者指南-目录篇

    前面的话 此教程适用于 ASP.NET MVC 5.x & Angularjs 1.x  的ABP框架(收费需要授权) 所以有能力的朋友还是希望你们多多支持 土牛.购买链接:https://w ...

  8. 忘记mysql数据库root密码

    找到配置文件my.ini  ,然后将其打开,可以选择用记事本打开,查找的方法如下: 打开后,搜索mysqld关键字 找到后,在mysqld下面添加skip-grant-tables,保存退出. PS: ...

  9. 基础知识系列☞关键字&srarr;virtual

    看到自己以前的一篇博客,感觉还差点什么,√,代码... using System; namespace Test { public class Program { private static voi ...

  10. Oracle&lpar;限定查询1&rpar;

    3.1.认识限定查询 例如:如果一张表中有100w条数据,一旦执行了“SELECT * FROM 表”语句之后,则将在屏幕上显示表中的全部数据行的记录,这样即不方便浏览,也有可能造成死机的问题出现,所 ...