H-Index II
2016-03-03 00:44
405 查看
Follow up for
H-Index: What if the
H-Index: What if the
citationsarray is sorted in ascending order? Could you optimize your algorithm?
class Solution { public: int hIndex(vector<int>& citations) { int n = citations.size(); if (n < 1) { return 0; } int left = 0; int right = n-1; while (left < right-1) { int mid = left + (right-left)/2; if (citations[mid] >= n-mid) { right = mid; } else { left = mid; } } if (citations[left] >= n-left) { return n-left; } else if (citations[right] >= n-right) { return n-right; } return 0; } };
相关文章推荐
- IOS--AFNetworking POST与GET请求
- MFC双缓冲绘图
- 20160303 - 升级 Windows 10 版本 1511 后,文件夹默认打开方式为 cmd 的修复
- 个人进阶之路——安卓蓝牙模块(4)
- Linux下使用C语言返回年月日
- W6s数据传输格式
- iOS 第三方 需要 引用的库
- 自定义垂直滚动切换TextView
- 关于React使用中遇到的坑
- Hibernate学习篇04——联合主键(一)
- Nginx运行和控制命令
- 自我介绍
- 微信公众号 “网络出错,轻触屏幕重新加载”
- 260. Single Number III
- (java)Binary Tree Preorder Traversal
- linux redis安装
- ios 多线程开发 GCD
- VisualSVN Server仓库迁移到Linux(包含所有版本, 权限,用户信息)
- Linux系统运维/vi的额外功能/4
- Mistakes in Python