leetcode 275: H-Index II
2015-09-05 17:09
369 查看
Follow up for
H-Index: What if the
[思路]
二分查找,
[CODE]
H-Index: What if the
citationsarray is sorted in ascending order? Could you optimize your algorithm?
[思路]
二分查找,
[CODE]
public class Solution { public int hIndex(int[] citations) { int n = citations.length; int low=0, high=n-1; while(low<=high) { int mid = low + (high-low)/2; if(citations[mid] == n-mid) return n-mid; else if(citations[mid] < n-mid) low = mid+1; else high = mid-1; } return n-low; } }
相关文章推荐
- LoRa无线通信设计(三)小区环境测试
- 内部类
- Leetcode|Sliding Window Maximum(multiset,优先队列,双端队列和区间树的应用)
- 数据库垂直拆分,水平拆分利器,cobar升级版mycat - freewebsys的专栏 - 博客频道 - CSDN.NET
- LISP记录
- eclipse启动闪退总结
- 数据库备份恢复时出现“无法处理,因为正由此会话使用”
- SqlHelper类
- c++primer之顺序容器(添加元素)
- flash乱码解决方案
- nginx 直接在配置文章中设置日志分割
- 源代码搭建LNMP环境
- 源代码搭建LNMP环境
- operator new在C++中的各种写法
- 去除字符串中的重复字符
- CRF分词的纯Java实现
- Robust Visual Tracking via Convolutional Networks 阅读笔记
- Ubuntu14.04下安装scrapy
- win10 internal power error
- POJ2337 Catenyms(欧拉回路+dfs)