LeetCode:H-Index II
来源:互联网 发布:精英男 知乎 编辑:程序博客网 时间:2024/05/16 15:33
H-Index II
Total Accepted: 24331 Total Submissions: 74459 Difficulty: Medium
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.
Subscribe to see which companies asked this question
Hide Similar Problems
思路:
承接上题【】,与上题不同之处在于已经是排序的,因此通过二分找到临界点即可。
java code:
public class Solution { public int hIndex(int[] citations) { if(citations == null || citations.length == 0) return 0; int len = citations.length; int lo = 0, hi = len-1; while(lo <= hi) { int mid = lo + (hi-lo)/2; if(citations[mid] == len - mid) return len-mid; else if(citations[mid] >= len - mid) hi = mid - 1; else lo = mid + 1; } return len-lo; }}
0 0
- 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
- leetcode之H-index &&H-index II
- [leetcode] 275.H-Index II
- leetcode 275: H-Index II
- CodeForces 671A Recycling Bottles
- Leetcode 43. Multiply Strings
- 三种页面置换算法C实现
- 火拼泡泡龙技巧以及一些技术简介
- 数据库表空间相关
- LeetCode:H-Index II
- (Caffe)基本类Blob,Layer,Net(一)
- 排序(三)之直接插入排序Straight Insertion Sort
- (Caffe)基本类Solver、Caffe、Batch(二)
- 第十三周项目—阅读、修改和运行关于交通工具类的程序(1)
- IOS--如何在UILabel上显示图片
- Hibernate+Spring整合时报错
- POJ 3249 Test for Job【SPFA】
- lightoj 1294 Positive Negative Sign 【规律】