leetcode 275: H-Index II
来源:互联网 发布:网络型数据采集机 编辑:程序博客网 时间:2024/05/21 12:46
Follow up for H-Index: What if the citations
array 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; }}
0 0
- leetcode 275: H-Index II
- Leetcode 275 : H-Index II
- [LeetCode 275] H-Index II
- LeetCode 275 H-Index II
- LeetCode 275 H-Index II
- LeetCode 275: H-Index II
- Leetcode: H-Index II
- Leetcode: H-Index II
- [LeetCode]H-Index II
- H-Index II -- leetcode
- LeetCode H-Index II
- leetcode H-Index II
- [Leetcode]H-Index II
- [LeetCode] H-Index II
- LeetCode -- H-Index II
- [LeetCode]H-Index II
- LeetCode:H-Index II
- 【Leetcode】H-Index II
- JAVA学习——多线程同步
- C++模板学习之单链表的实现
- CRF分词的纯Java实现
- flash乱码解决方案
- c++primer之顺序容器(添加元素)
- leetcode 275: H-Index II
- 有图有话 | 高效人士的一天,你能做到几条?
- SqlHelper类
- eclipse启动闪退总结
- 内部类
- iOS8的远程推送
- (决策分析思考)Decision Analytic Thinking
- 欢迎使用CSDN-markdown编辑器
- Java线程:线程栈模型与线程的变量