Algorithms—275.H-Index II
2015-09-06 15:42
417 查看
思路:二分法。
public class Solution {
public int hIndex(int[] citations) {
if (citations.length==0) {
return 0;
}
Arrays.sort(citations);
int s=0;
int e=citations.length-1;
int m=(s+e)/2;
int l=citations.length;
while (e-s>1) {
if (l<citations[s]+s) {
return l;
}
if (l==citations[m]+m) {
return l-m;
}
if (l>citations[m]+m) {
s=m;
}else {
e=m;
}
m=(s+e)/2;
}
if (l>citations[e]+e) {
return l-e-1;
}else if(l>citations[s]+s){
return l-e;
}else{
return l-s;
}
}
}
public class Solution {
public int hIndex(int[] citations) {
if (citations.length==0) {
return 0;
}
Arrays.sort(citations);
int s=0;
int e=citations.length-1;
int m=(s+e)/2;
int l=citations.length;
while (e-s>1) {
if (l<citations[s]+s) {
return l;
}
if (l==citations[m]+m) {
return l-m;
}
if (l>citations[m]+m) {
s=m;
}else {
e=m;
}
m=(s+e)/2;
}
if (l>citations[e]+e) {
return l-e-1;
}else if(l>citations[s]+s){
return l-e;
}else{
return l-s;
}
}
}
相关文章推荐
- Algorithms—274.H-Index
- Google三篇论文中文版
- golang debug with LiteIDE
- Goods:购物车模块之全选按钮与条目之复选按钮的click事件
- Go环境搭建
- UVA 11292 - Dragon of Loowater
- 奇虎360 和 Go
- Google也许要重回中国市场了
- mongo中$push的$slice子操作符的理解
- leetcode: (35) Search Insert Position
- Algorithms - Week 3-0 Mergesort
- Algorithms - Week 2-1 Elementary Sorts
- Goods:查询某个用户的购物车条目以及添加购物车条目
- Intent中的四个重要属性——Action、Data、Category、Extras
- go-tour-zh离线安装
- golang-反射机制
- godaddy.com 注册域名 买卖域名
- [转]为什么GOF的23种设计模式里面没有MVC?
- mongo备份与恢复工具的对比与说明
- 外媒:Google Play将重返中国大陆