<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 ...
随机推荐
- java8 LinkedHashMap 原理
LinkedHashMap 原理 基于jdk1.8 HashMap原理:http://www.cnblogs.com/zhaojj/p/7805376.html LinkedHashMap 继承Has ...
- 在使用confluent-kafka-go 时遇到如下问题
问题 $ go build t.go # pkg-config --cflags rdkafka Package rdkafka was not found in the pkg-config sea ...
- N!(hdu1042)
N! Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N! Input One N in one line, process ...
- MySQL锁表查询SQL
// 查看进程 SHOW PROCESSLIST; // 查看是否锁表 SHOW OPEN TABLES WHERE In_use > 0; // 查看正在锁的事务 SELECT * FROM ...
- Python urlib 模块
Python urlib 模块 urlib 模块 当前再爬虫领域使用的比较少,不过它对图片爬取处理会比较方便.这里我们只使用它的图片爬取. 使用 urlib.request.urlretrieve(u ...
- Python platform 模块
Python platform 模块 platform 模块用于查看当前操作系统的信息,来采集系统版本位数计算机类型名称内核等一系列信息. 使用方法: import platform # 获取操作系统 ...
- kali渗透综合靶机(十八)--FourAndSix2靶机
kali渗透综合靶机(十八)--FourAndSix2靶机 靶机下载地址:https://download.vulnhub.com/fourandsix/FourAndSix2.ova 一.主机发现 ...
- PHP 日历函数手册
PHP日历函数安装>>> 函数名称 描述 cal_days_in_month 返回某个历法中某年中某月的天数 cal_from_jd 转换Julian Day计数到一个支持的历法. ...
- AD读取Excel新建客户邮箱的测试环境部署有感
现有AD的账户操作所有服务几乎用WebApi方式,此 方法是便于搭建和部署,做到了前后端的分离 ,其中验证Exchange邮箱转发模块时发现foxmail的exchange本地邮箱配置极其简单,以此记 ...
- tomcat特殊字符处理问题解决方案
tomcat特殊字符处理问题解决方案 直接加上如下代码,本质是通过反射加上过滤字符 @Configuration public class TomcatConfig { @Bean public Co ...