landscapemi的博客

###### leetcode :Binary Search： H-Index IIe(275)

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;
}
};

#### [leetcode] 275.H-Index II

2015-09-05 17:00:53

#### [leetcode-275]H-Index II(java)

2015-09-06 08:57:22

#### Unique Binary Search Trees -- LeetCode

2014-04-30 06:16:29

#### LeetCode 99:Recover Binary Search Tree

2015-12-28 15:37:36

#### LeetCode | Unique Binary Search Trees II

2013-12-23 14:58:40

#### leetcode 173: Binary Search Tree Iterator

2015-01-02 12:44:56

#### Convert Sorted List to Binary Search Tree -- LeetCode

2014-04-17 07:57:02

#### 【LeetCode】669 Trim a Binary Search Tree

2017-09-08 15:53:21

#### LeetCode96:Unique Binary Search Trees

2015-06-24 15:56:10

#### LeetCode99—Recover Binary Search Tree

2016-03-19 22:12:41

## 不良信息举报

leetcode :Binary Search： H-Index IIe(275)