Skip to content

Commit a920f55

Browse files
add 275
1 parent 7864595 commit a920f55

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ Your ideas/fixes/algorithms are more than welcome!
276276
|278|[First Bad Version](https://leetcode.com/problems/first-bad-version/)|[Solution](../master/src/main/java/com/fishercoder/solutions/FirstBadVersion.java)| O(logn)|O(1) | Easy| Binary Search
277277
|277|[Find the Celebrity](https://leetcode.com/problems/find-the-celebrity/)|[Solution](../master/src/main/java/com/fishercoder/solutions/FindtheCelebrity.java)| O(n)|O(1) | Medium|
278278
|276|[Paint Fence](https://leetcode.com/problems/paint-fence/)|[Solution](../master/src/main/java/com/fishercoder/solutions/PaintFence.java)| O(n)|O(1) | Easy| DP
279+
|275|[H-Index II](https://leetcode.com/problems/h-index-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_275.java)| O(logn)|O(1) | Medium| Binary Search
279280
|274|[H-Index](https://leetcode.com/problems/h-index/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_274.java)| O(nlogn)|O(1) | Medium|
280281
|273|[Integer to English Words](https://leetcode.com/problems/integer-to-english-words/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_273.java)| O(n)|O(1) | Hard| Math, String
281282
|272|[Closest Binary Search Tree Value II](https://leetcode.com/problems/closest-binary-search-tree-value-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/ClosestBinarySearchTreeValueII.java)| O(h+k)|O(h) | Hard| Stack

Diff for: src/main/java/com/fishercoder/solutions/_275.java

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions;
2+
3+
/**
4+
* 275. H-Index II
5+
* Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?
6+
*/
7+
public class _275 {
8+
9+
public int hIndex(int[] citations) {
10+
int left = 0;
11+
int len = citations.length;
12+
int right = len-1;
13+
while (left <= right) {
14+
int mid = left + (right-left)/2;
15+
if (citations[mid] >= (len - mid)) {
16+
right = mid - 1;
17+
} else {
18+
left = mid + 1;
19+
}
20+
}
21+
return len - left;
22+
}
23+
24+
}

0 commit comments

Comments
 (0)