H-Index II
来源:互联网 发布:记账app 知乎 编辑:程序博客网 时间:2024/05/19 09:16
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 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; }};
0 0
- H-Index && H-Index II
- Leetcode: H-Index II
- Leetcode: H-Index II
- H index II
- [LeetCode]H-Index II
- H-Index II -- leetcode
- LeetCode H-Index II
- leetcode H-Index II
- [275]H-Index II
- [Leetcode]H-Index II
- [LeetCode] H-Index II
- H-Index II
- LeetCode -- H-Index II
- 275、H-Index II
- Leetcode188: H-Index II
- H-Index II
- H-Index II
- 275. H-Index II
- ***LeetCode 90 Subsets ii
- php性能优化学习记录一
- 面试
- 关于React使用中遇到的坑
- 个人进阶之路——安卓蓝牙模块(4)
- H-Index II
- unity——角色控制以及网络组件
- Hibernate学习篇05——联合主键(二)
- thinkphp3.2.3开发商城实战(一)
- 栈与队列
- 深入探讨 Java 类加载器
- *LeetCode 90
- 错误记录:Resource ID #0x7f040006 type #0x12 is not valid
- 网易公开课《Linux内核分析》学习心得-mykernel实验的实践和分析