[Leetcode]H-Index II
来源:互联网 发布:微信用户分析数据接口 编辑:程序博客网 时间:2024/05/19 13:24
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 inO(log n) and the input is sorted.
class Solution {public: /*algorithm: binary search time O(nlogn) space O(1) */ int hIndex(vector<int>& citations) { int n = citations.size(); int l = 0,r = n-1; while(l <= r){ int h = l + (r-l)/2; if(citations[h] == n-h)return n-h; else if(citations[h] > n-h)r = h-1; else l = h+1; } return n-l; }};
0 0
- 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
- Leetcode H-Index II
- leetcode:H-Index II
- LeetCode H-index and H-index II
- leetcode之H-index &&H-index II
- [leetcode] 275.H-Index II
- leetcode 275: H-Index II
- 你应该成为 Web 开发者的 5 大理由—兄弟连IT教育
- 微信公众号开发sprintf()函数其中%S等符号的说明
- 矢量叉积判断顺时针还是逆时针
- 前端开发面试题
- Android源码编译
- [Leetcode]H-Index II
- 一个文本框的随想
- EventBus的好
- myeclipse中更改默认的编码
- 玩转Visual Studio-理解多字节编码和Unicode编码
- (二)MQ、JMS以及ActiveMQ
- Python遍历文件夹中文件
- Codevs_P2370 小机房的树(LCA)
- NoSQL数据库的四大分类表格分析