<Array> 274 275
274. H-Index
这道题让我们求H指数,这个质数是用来衡量研究人员的学术水平的质数,定义为一个人的学术文章有n篇分别被引用了n次,那么H指数就是n.
用桶排序,按引用数从后往前计算论文数量,当论文数 >= 当前引用下标时。满足至少有N篇论文分别被引用了n次。
class Solution {
public int hIndex(int[] citations) {
int n = citations.length;
int[] bucket = new int[n + 1];
for(int c : citations){
if(c >= n){
bucket[n]++;
}else{
bucket[c]++;
}
}
int count = 0;
for(int i = n; i >= 0; i--){
count += bucket[i];
if(count >= i){
return i;
}
}
return 0;
}
}
275. H-Index II
有len - mid篇文章,每篇文章至少有 citations[ mid ] 次引用。
1. len - mid == citations[ mid ], 符合
2. len - mid > citations[ mid ] , 文章数 》 引用次数,不符合定义,往右搜索
3. len - mid < citations[ mid ], 文章数 《 引用次数,符合定义,但说明可能有更多的文章每篇被引用citations[ mid ] 次, 往左搜索。
len - (right + 1 ) = 总文章数 - 不符合定义的文章数。
class Solution {
public int hIndex(int[] citations) {
int len = citations.length;
int left = 0, right = len - 1;
while(left <= right){
int mid = left + (right - left) / 2;
if(len - mid == citations[mid]){
return citations[mid];
} else if( len - mid > citations[mid]){
left = mid + 1;
}else{
right = mid - 1;
}
}
return len - (right + 1);
}
}
<Array> 274 275的更多相关文章
- 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 ...
- ***CodeIgniter集成微信支付(转)
微信支付Native扫码支付模式二之CodeIgniter集成篇 http://www.cnblogs.com/24la/p/wxpay-native-qrcode-codeigniter.html ...
- Bitmap vs 2Bitmap的实现
[本文链接] http://www.cnblogs.com/hellogiser/p/bitmap-vs-2bitmap.html [题目] 在2.5亿个整数找出不重复的整数,内存不足以容纳着2.5亿 ...
- java中常用的工具类(三)
继续分享java中常用的一些工具类.前两篇的文章中有人评论使用Apache 的lang包和IO包,或者Google的Guava库.后续的我会加上的!谢谢支持IT江湖 一.连接数据库的综合类 ...
- java中常用的工具类(二)
下面继续分享java中常用的一些工具类,希望给大家带来帮助! 1.FtpUtil Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
- PHP和Golang使用Thrift1和Thrift2访问Hbase0.96.2(ubuntu12.04)
目录: 一.Thrift1和Thrift2的简要介绍 1) 写在前面 2) Thrift1和Thrift2的区别 二.Thrift0.9.2的安装 1) 安装依赖插件 2) Thrift0.9.2的 ...
- linux设备驱动归纳总结(十三):1.触摸屏与ADC时钟【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-119723.html linux设备驱动归纳总结(十三):1.触摸屏与ADC时钟 xxxxxxxxxx ...
- ecshop init.php文件分析
1. ecshop init.php文件分析 2. <?php 3. 4. /** 5. * ECSHOP 前台公用文件 6. * ===================== ...
- Linux设备模型分析之kset(基于3.10.1内核)
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 内核版本:3.10.1 一.kset结构定义 kset结构体定义在include/linux/kobject.h ...
随机推荐
- python yield from (一)
1. yield from 会抛出iterator中所有的值:而yield只是抛出传进来的值,如果是值,就抛出值,如果是iterator对象,抛出iterator对象 def g1(iterable) ...
- mybaties报错:There is no getter for property named 'table' in 'class java.lang.String'
报错是由于xml里获取不到这个table参数 package com.xxx.mapper; import java.util.List; import org.apache.ibatis.annot ...
- WPF 中如何变相让 ListBox 宽度(Width) 100%,高度(Height) 100%,从而达到 Filled 的效果
直接贴代码了: XAML: <Window x:Class="HelloWorld.MainWindow" xmlns="http://schemas.micros ...
- yum 找不到程序,yum更换国内阿里源
使用百度云服务器,发现百度yum源非常不稳定,果断采用阿里源,操作步骤如下: 一.备份 $ cd /etc/yum.repos.d/ $ mv baidu-bcm.repo baidu-bcm.rep ...
- ASP.NET Core 进程外(out-of-process)托管
ASP.NET Core 进程外(out-of-process)托管 在本节中,我们将讨论 ASP.NET Core 中的Out Of Process Hosting. ASP.NET Core 进程 ...
- Winform中使用控件的Dock属性设计窗体布局,使不随窗体缩放而改变
场景 在新建一个Winform窗体后,拖拽控件设置其布局如下 如果只是单纯的这么设计,我们在运行后,如果对窗口进行缩放就会导致如下 所以我们需要在设计页面布局时对控件进行定位设置. 注: 博客主页:h ...
- Spring Boot 使用 Log4j2 & Logback 输出日志到 EKL
文章目录 1.ELK 介绍 2.环境.软件准备 3.ELK 环境搭建 4.Spring Boot 配置示例 4.1.Log4j2 方式配置 4.2.Logback 方式配置 1.ELK 介绍 ELK ...
- 实验6:Mapreduce实例——WordCount
实验目的1.准确理解Mapreduce的设计原理2.熟练掌握WordCount程序代码编写3.学会自己编写WordCount程序进行词频统计实验原理MapReduce采用的是“分而治之”的 ...
- mpvue小程序开发之 实现一个弹幕评论
先上图 就是一个简单的弹幕发送功能 弹幕区的页面: <div class="content" v-show="doommData.length"> ...
- 四.Windows基础
系统目录 Windows Program files 用户 Perflogs:是Windows7的日志信息,如磁盘扫描错误信息,删掉可以,但不建议删,删掉反而降低系统速度,perflogs是系统自动生 ...