275. H-Index II 递增排序后的论文引用量
[抄题]:
Given an array of citations in ascending order (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 hcitations each."
Example:
Input:citations = [0,1,3,5,6]
Output: 3
Explanation:[0,1,3,5,6]
means the researcher has5
papers in total and each of them had
received 0, 1, 3, 5, 6
citations respectively.
Since the researcher has3
papers with at least3
citations each and the remaining
two with no more than3
citations each, his h-index is3
.
[暴力解法]:
时间分析:
空间分析:
[优化后]:
时间分析:
空间分析:
[奇葩输出条件]:
[奇葩corner case]:
[思维问题]:
从后往前积累的count = length - 从前往后的index
[一句话思路]:
甚至都不知道排序之后要用二分法,算是积累经验了
[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):
[画图]:
[一刷]:
- 明确这道题需要找的target: len - index代表文章数量
- 还是只有if elseif else的结构才是完整的
[二刷]:
[三刷]:
[四刷]:
[五刷]:
[五分钟肉眼debug的结果]:
[总结]:
排序之后要用二分法
[复杂度]:Time complexity: O(lgn) Space complexity: O(n)
[英文数据结构或算法,为什么不用别的数据结构或算法]:
[算法思想:递归/分治/贪心]:
[关键模板化代码]:
非九章还加了等号,感觉就是因题目而异吧
while (lo <= hi) {
int med = (hi + lo) / 2;
[其他解法]:
[Follow Up]:
[LC给出的题目变变变]:
[代码风格] :
class Solution {
public int hIndex(int[] citations) {
//cc
if (citations == null || citations.length == 0) return 0; //ini: length
int n = citations.length, start = 0, end = n - 1; //for loop
while (start <= end) {
int mid = (end + start) / 2;
if (citations[mid] == n - mid) return n - mid;
else if (citations[mid] > n - mid) end = mid - 1;
else start = mid + 1;
} return n - start;
}
}
275. H-Index II 递增排序后的论文引用量的更多相关文章
- Java实现 LeetCode 275 H指数 II
275. H指数 II 给定一位研究者论文被引用次数的数组(被引用次数是非负整数),数组已经按照升序排列.编写一个方法,计算出研究者的 h 指数. h 指数的定义: "h 代表"高 ...
- Leetcode之二分法专题-275. H指数 II(H-Index II)
Leetcode之二分法专题-275. H指数 II(H-Index II) 给定一位研究者论文被引用次数的数组(被引用次数是非负整数),数组已经按照升序排列.编写一个方法,计算出研究者的 h 指数. ...
- <二分查找+双指针+前缀和>解决子数组和排序后的区间和
<二分查找+双指针+前缀和>解决子数组和排序后的区间和 题目重现: 给你一个数组 nums ,它包含 n 个正整数.你需要计算所有非空连续子数组的和,并将它们按升序排序,得到一个新的包含 ...
- 将1~n个整数按字典顺序进行排序,返回排序后第m个元素
给定一个整数n,给定一个整数m,将1~n个整数按字典顺序进行排序,返回排序后第m个元素.n最大可为5000000.字典排序的含义为:从最高位开始比较.1开头的数字排在最前面,然后是2开头的数字,然后是 ...
- Javascript 数组自定义排序,并获取排序后的保存原索引的同序数组(堆排序实现)
比如数组A: [ 0: 5, 1: 2, 2: 4, 3: 3, 4: 1 ] 排序后的结果为:[1, 2, 3, 4, 5],但是有时候会有需求想要保留排序前的位置到一个同位数组里,如前例则为:[4 ...
- [LeetCode] Max Chunks To Make Sorted II 可排序的最大块数之二
This question is the same as "Max Chunks to Make Sorted" except the integers of the given ...
- 42.输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S, 如果有多对数字的和等于S,输出两个数的乘积最小的。
输入一个递增排序的数组和一个数字S,在数组中查找两个数,使得他们的和正好是S, 如果有多对数字的和等于S,输出两个数的乘积最小的. 这道题有很多烟雾弹: 首先如果有多对,最前面的两个数就是乘积最小的, ...
- 【C语言】求旋转数组的最小数字,输入一个递增排序的数组的一个旋转,输出其最小元素
//求旋转数组的最小数字,输入一个递增排序的数组的一个旋转,输出其最小元素 #include <stdio.h> #include <string.h> int find_mi ...
- Manthan, Codefest 16 H. Fibonacci-ish II 大力出奇迹 莫队 线段树 矩阵
H. Fibonacci-ish II 题目连接: http://codeforces.com/contest/633/problem/H Description Yash is finally ti ...
随机推荐
- 在Mac OS上搭建Python的开发环境
本文转载自:http://www.jb51.net/article/76931.htm 一. 安装python mac系统其实自带了一个python的执行执行环境,用来运行python还行,但是开发可 ...
- 轻量级封装DbUtils&Mybatis之二Dbutils
DbUtils入门 Apache出品的极为轻量级的Jdbc访问框架,核心类只有两个:QueryRunner和ResultSetHandler. 各类ResultSetHandler: ArrayHan ...
- 1-3 superset数据模型
在models.py中大部分的class对应数据库中的表,那么我们就从AuditMixinNullable这个类开始我们的模型解析. AuditMixin:这个类是FAB(Flask AppBuil ...
- springboot+idea 热部署
1 配置pom.xml <!--spring-boot-devtools 热部署--> <dependency> <groupId>org.springframew ...
- java代码-----------逻辑运算符、 &&逻辑与 ||或
总结: && :两者均满足.是true ||: 两者中有一个满足就为true,不然就是false package com.sads; public class shou { publi ...
- SpringMVC之八:基于SpringMVC拦截器和注解实现controller中访问权限控制
SpringMVC的拦截器HandlerInterceptorAdapter对应提供了三个preHandle,postHandle,afterCompletion方法. preHandle在业务处理器 ...
- Hive使用druid做连接池代码实现
配置文档 hive_jdbc_url=jdbc:hive2://192.168.0.22:10000/default hive.dbname=xxxxx hive_jdbc_username=root ...
- Error 20002 (severity 9):Adaptive Server connection failed
环境: Ubuntu12.10_x64 问题: 用tsql访问SQL Server >> tsql -H U sa Error (severity ): Adaptive Server c ...
- line 3: /usr/local/arm/4.3.2/bin/arm-none-linux-gnueabi-gcc: No such file or directory
sudo apt-get install lib32ncurses5(网上下载的很多arm-linux-gcc都是32位的,64位的ubuntu需要按此包)
- 缓存varnish的管理及配置详解
一 工作原理 在当前主流的Web服务架构体系中,Cache担任着越来越重要的作用.常见的基于浏览器的C/S架构,Web Cache更是节约服务器资源的关键.而最近几年由FreeBSD创始人之一Kamp ...