leetcode :Binary Search:H-Index IIe(275)
来源:互联网 发布:央视市场研究 知乎 编辑:程序博客网 时间:2024/06/06 19:08
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?
Expected runtime complexity is in O(log n) and the input is sorted.
class Solution {public: // binary search - O(log(n)) int hIndex(vector<int>& citations) { int n = citations.size(); int low = 0, high = n-1; while( low <= high ) { int mid = low + (high-low)/2; if (citations[mid] == n - mid) { return n - mid; }else if (citations[mid] > n-mid){ high = mid - 1; }else { low = mid + 1; } } return n-low; }};
0 0
- leetcode :Binary Search:H-Index IIe(275)
- [leetcode][Binary Search] H-Index II
- Binary Search: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(java)
- [leetcode 274 275]H-Index I II
- LeetCode 274/275 H-Index Java
- [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 274 : H-index
- leetcode H-Index
- 替换字符串中部分字符串,java
- 关于nmap和traceroute在虚拟机里使用的问题
- SpringMVC返回json数据时乱码解决
- 链表------创建删除增加遍历
- java学习例题之数据加密
- leetcode :Binary Search:H-Index IIe(275)
- 【任玉刚】给Android程序员的一些面试建议
- Hdu 4335 What is N? 欧拉函数降幂公式 + 循环节
- .h头文件,.lib库文件和.dll关系
- Java中string和stringBuffer的区别
- Touch事件的传递机制?
- 又一电源问题引发的灾难
- LINK:fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- node.js浅谈