274. 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.
代码如下:
public class Solution {
public int hIndex(int[] citations) {
if(citations.length==0)
return 0; Arrays.sort(citations);
if(citations[citations.length-1]==0)
return 0;
if(citations[0]>=citations.length)
return citations.length;
int length=0;
for(int i=0;i<citations.length;i++)
{
length=citations.length-i;
if(citations[i]>=length)
{
int count=0;
if(citations[i]>=length)
{
for(int j=0;j<i;j++)
{
if(citations[j]>=length)
count++;
}
if(count<=length)
return length;
}
}
}
return length;
}
}
274. H-Index的更多相关文章
- Java实现 LeetCode 274 H指数
274. H指数 给定一位研究者论文被引用次数的数组(被引用次数是非负整数).编写一个方法,计算出研究者的 h 指数. h 指数的定义: "h 代表"高引用次数"(hig ...
- Leetcode 274.H指数
H指数 给定一位研究者论文被引用次数的数组(被引用次数是非负整数).编写一个方法,计算出研究者的 h 指数. h 指数的定义: "一位有 h 指数的学者,代表他(她)的 N 篇论文中至多有 ...
- HDU-6278-Jsut$h$-index(主席树)
链接: https://vjudge.net/problem/HDU-6278 题意: The h-index of an author is the largest h where he has a ...
- [LeetCode] 274. H-Index H指数
Given an array of citations (each citation is a non-negative integer) of a researcher, write a funct ...
- jQuery—一些常见方法(1)【filter(),not(),has(),next(),prev(),find(),eq(),index(),attr(),】
1.filter()和not()方法 filter()和not()是一对反方法,filter()是过滤. filter()方法是针对元素自身.(跟has()方法有区别) <script type ...
- FFmpeg的H.264解码器源代码简单分析:熵解码(Entropy Decoding)部分
===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...
- LeetCode(274)H-Index
题目 Given an array of citations (each citation is a non-negative integer) of a researcher, write a fu ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
- openssl 1.1.1 reference
openssl 1.1.1 include/openssl aes.h: # define HEADER_AES_H aes.h: # define AES_ENCRYPT 1 aes.h: # de ...
- openssl-1.1.0g reference
include/openssl aes.h: struct aes_key_st { aes.h: unsigned long rd_key[4 * (AES_MAXNR + 1)]; aes.h: ...
随机推荐
- 判断一个字符串是否为有效ip地址
bool f (const char *s) { int s1,s2,s3,s4; ) { return false; } if ((s1 & 0xffffff00) || (s2 & ...
- C- struct的使用
数组是二等公民,不能进行整体赋值,或者参数传递,或者作为返回值. But!如果封装在struct内部,就完全不一样了 #include <iostream> using namespace ...
- Opencv的基础结构与内容
- URAL 1158 AC自动机上的简单DP+大数
题目大意 在一种语言中的字母表中有N(N<=50)个字母,每个单词都由M(M<=50)个字母构成,因此,一共可以形成N^M个单词.但是有P(P<=10)个串是被禁止的,也就是说,任何 ...
- android listview综合使用示例_结合数据库操作和listitem单击长按等事件处理
本示例说明: 1.自定义listview条目样式,自定义listview显示列数的多少,灵活与数据库中字段绑定. 2.实现对DB的增删改查,并且操作后listview自动刷新. 3.响应用户操作点击事 ...
- 有哪些 PHP 调试技巧?
我目前遇到的最让我称赞的debug方式是:xdebug的 xdebug_start_trace(); /* 业务代码 */ xdebug_stop_trace(); 他解决了我长久以来一个代码调试问题 ...
- Geetest 极验验证 验证图片拼图
今天要求做一个跟魅族官网登陆的一个验证效果一样的界面 是一个拖动滑动图片进行拼图 那个效果看着很好,刚开始拿到不知道好不好做 从网上搜资料发现这是一种“极验验证码” 让用户通过滑动拼图来进行验证. 网 ...
- vc设置按钮文字颜色
设置按钮文字颜色使用 CMFCBUTTON即可 在OnInitDialog函数加入如下内容即可 ((CMFCButton*)GetDlgItem(IDC_MFCBUTTON1))->SetTex ...
- 首席技术官 (CTO) 比普通程序员强在哪
互联网的蓬勃发展,让无数的程序员身价水涨船高,都变成了「香饽饽」,更有了不少「创业」,「当上 CTO,迎娶白富美的传说」.都说不想当元帅的士兵不是好士兵,我觉得这件事见仁见智,但提升自己的价值,让自己 ...
- hdoj-2025
#include "stdio.h"#include "string.h"void sort(char ch[],int count[],int n,int f ...