[LeetCode 275] H-Index II
来源:互联网 发布:php 日期格式转时间戳 编辑:程序博客网 时间:2024/06/08 02: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 inO(log n) and the input is sorted.
solution:
Binary search.
public int hIndex(int[] citations) { if(citations.length <=0) return 0; int len = citations.length; int start = 0; int end = len-1; while(start<=end) { int mid = start + (end-start)/2; if(citations[mid] == len-mid) return len-mid; else if (citations[mid] < len-mid) start = mid+1; else end = mid-1; } return len-start; }
0 0
- 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: 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
- js 工作小记
- iOS开发 status bar 改成白色 (iOS9)
- 9.17整型常量
- 10个iPhone开发网站、论坛、博客
- Tyvj 2016 (Clover 9) 外星人 字符串匹配:KMP
- [LeetCode 275] H-Index II
- 今日学习总结9.18
- iOS音乐播放器详解(MusicPlayer1.0)
- C3P0的详细配置
- sybase 事务 not allowed within a multi-statement transaction
- java.lang.ClassNotFoundException与java.lang.NoClassDefFoundError的区别
- 期望求解
- JavaScript中实现键值对的方法
- DBCP的配置参数