275. H-Index II
来源:互联网 发布:仓库管理php源码 编辑:程序博客网 时间:2024/05/22 02:54
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.
思路:二分查找。
class Solution {public:int hIndex(vector<int>& citations) {int left = 0;const int size = citations.size();int right = size;while (left < right){int mid = (left + right) / 2;if (citations[mid] >= size - mid){right = mid;}else{left = mid + 1;}}return size-left;}};
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
- 记沪江之行
- 关于android系统Binder机制解析
- 安装oracle12c后,用dbca建数据库老遇到ora-12560错误的解决策
- Leetcode-container-with-most-water
- 键盘移动div样例
- 275. H-Index II
- Spring bean 设值注入和 构造注入
- springmvc controller ajax 一些使用说明
- SimpleNet网络框架源码分析
- 银行家算法的实现,有关进程资源分配的算法
- spring 2 bean配置--基本配置
- java.util.ConcurrentModificationException错误
- com.alibaba.dubbo.rpc.RpcException的解决方法
- JS跨域:1.解决方案之-SpringMVC拦截器