275、H-Index II
来源:互联网 发布:arduino 单片机 编辑:程序博客网 时间:2024/05/20 01:10
题目:
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.
解题思路:
很明显,此题要考虑使用二分查找。但对于具体做的方法还是不太明白,希望以后能弄懂。
c++版本:
class Solution {public: int hIndex(vector<int>& citations) { int n=citations.size(),lo=0,hi=n-1; while(lo<=hi) { int mid = (lo+hi)>>1; if(citations[mid]==n-mid)return n-mid; else if(citations[mid]>n-mid)hi=mid-1; else lo=mid+1; } return n-lo; }};
0 0
- [275]H-Index II
- 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 275: H-Index II
- H-Index && H-Index II
- [leetcode-275]H-Index II(java)
- [leetcode 274 275]H-Index I II
- [leetcode] 274 275 H-Index I && II
- LeetCode(275)H-Index II
- 【LEETCODE】275-H-Index II [Python]
- LeetCode.274(275) H-Index && II
- Leetcode: H-Index II
- Leetcode: H-Index II
- H index II
- 网络IPC:套接字值寻址
- 驱动测试错误集锦
- android 网络异常提示
- -webkit-text-size-adjust: none;
- 【模板】【bzoj3224】Tyvj 1728 普通平衡树 Splay
- 275、H-Index II
- 模拟快递100请求 通过快递单号获取物流信息
- 多线程操作之线程概念
- mysql查询所有记录,并去掉重复的记录
- SDWebImage内部实现过程
- 英国MBA专业
- Android shape的使用笔记
- windows下Eclipse JDK环境变量配置 Tomcat配置
- Servlet的认识