[leetcode][Binary Search] H-Index II
来源:互联网 发布:腾讯数据库有多大 编辑:程序博客网 时间:2024/06/07 06:11
题目:
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) {if (citations.empty()) return 0;int n = citations.size();int low = 0, high = n - 1;int h = 0;while (high >= low){int mid = low + (high - low) / 2;//找到,直接返回if ((n - mid) == citations[mid]) return n - mid;//更新hint hNew = ((n - mid) < citations[mid])?(n-mid):citations[mid];if (h < hNew) h = hNew;//二分查找if ((n - mid) < citations[mid]) high = mid - 1;else low = mid + 1;}return h;}};
0 0
- [leetcode][Binary Search] H-Index II
- Binary Search:275. H-Index II
- leetcode :Binary Search:H-Index IIe(275)
- 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
- PE格式详细讲解8 – 输入表
- STL中的所有容器资料
- 《机器学习实战》学习笔记:绘制树形图&使用决策树预测隐形眼镜类型
- Cocos 2d-x 3.6 touch事件只有began 坑~
- 解决android:background背景图片被拉伸问题
- [leetcode][Binary Search] H-Index II
- android学习笔记(17)广播事件处理进阶(注册方法)
- IOS中宏定义
- java 解决中文乱码
- Swift UIButton UIButtonType
- android 制作9.png图片
- Go环境搭建
- MSSQL数据库测试连接的快捷方法
- Java获取时间范围: 当前季度,上个季度,昨天,当前月,上个月