Leetcode 275. H-Index II
来源:互联网 发布:万万没想到网络剧 编辑:程序博客网 时间:2024/06/16 00:03
Follow up for H-Index: What if the citations
array is sorted in ascending order? Could you optimize your algorithm?
接上一篇,数组升序排列。
一看就是二分,需要注意边界,仔细想想。
class Solution {public: int hIndex(vector<int>& citations) { int mid = -1, l = 0, r = citations.size()-1; while(l <= r) { mid = (l + r) >> 1; if(citations.size() - mid == citations[mid]) return citations[mid]; else if(citations.size() - mid > citations[mid]) l = mid + 1; else r = mid - 1; } return citations.size() - r - 1; }};
1 0
- [leetcode] 275.H-Index II
- 275. H-Index II LeetCode
- 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】 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
- c++迭代器详解(一):back_inserter, front_inserter,inserter
- the diary of process manage of top ps and kill in linux
- SecureCRT显示乱码的解决办法
- 骄傲的代价
- JEM 5.0.1 学习心得
- Leetcode 275. H-Index II
- linux系统源码包软件安装步骤
- Ubuntu文件管理器的默认设置
- 基于TCP/IP的迭代回声服务器/客户端
- vuejs2.0详细教程,结合Api文档
- Numpy的广播机制
- ACM刷题之codeforces————The Little Match Girl
- Matlab 体验
- TLPI-Ch24