275. H-Index II
来源:互联网 发布:怎样开发app软件 编辑:程序博客网 时间:2024/05/22 05:12
Follow up for H-Index: What if the citations
array is sorted in ascending order? Could you optimize your algorithm?
Hint:
- Expected runtime complexity is in O(log n) and the input is sorted.
public static int hIndex(int[] citations) { int start = 0; int end = citations.length - 1; int n = citations.length; while(start <= end){ int middle = (start + end) / 2; if(citations[middle] == n - middle){ return n - middle; } if(citations[middle] > n - middle){ end = middle - 1; }else{ start = middle + 1; } } return n - start; }
0 0
- 275. H-Index II
- 275. H-Index II
- 275. H-Index II
- 275. H-Index II
- 275. H-Index II
- 275. H-Index II
- 275. H-Index II
- 275. H-Index II
- 275. H-Index II
- 275. H-Index II
- 275. H-Index II
- 275. H-Index II
- 275. H-Index II
- 275. H-Index II
- 275. H-Index II
- 274. H-Index & 275. H-Index II
- [leetcode] 275.H-Index II
- 275. H-Index II LeetCode
- 机器学习笔记
- 软硬件调试九法:第三条规则 不要想而要看
- The 3n + 1 problem
- 为啥公司愿花更多钱从外面招人
- 微软Hololens应用及开发——HoloLens介绍篇(一)全息图介绍
- 275. H-Index II
- Mac 校园网有线网络配置
- Mac上安装spark过程
- Python 进阶—— list 的头插和尾插
- 修改Tomcat的端口号
- Javascript:谈谈JS的全局变量跟局部变量
- LMS算法
- 重建二叉树
- Python 数据结构与算法——列表(链表,linked list)