Skip to content

Commit 39d15aa

Browse files
committed
h-index ii
1 parent 68a9020 commit 39d15aa

File tree

3 files changed

+76
-53
lines changed

3 files changed

+76
-53
lines changed

.idea/workspace.xml

Lines changed: 49 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,4 @@ codes may not be optimized
430430
1. [Permutation Sequence](https://leetcode.com/problems/permutation-sequence/description/)
431431
1. [Next Permutation](https://leetcode.com/problems/next-permutation/description/)
432432
1. [H-Index](https://leetcode.com/problems/h-index/description/)
433+
1. [H-Index II](https://leetcode.com/problems/h-index-ii/description/)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.github.chen0040.leetcode.day21.medium;
2+
3+
4+
/**
5+
* Created by xschen on 16/8/2017.
6+
*
7+
* link: https://leetcode.com/problems/h-index-ii/description/
8+
*/
9+
public class HIndexII {
10+
public class Solution {
11+
public int hIndex(int[] citations) {
12+
int lo = 0;
13+
int hi = citations.length - 1;
14+
while(lo <= hi) {
15+
int mid = lo + (hi-lo) / 2;
16+
int h = citations.length - mid;
17+
if(citations[mid] < h){
18+
lo = mid + 1;
19+
} else if(citations[mid] >= h) {
20+
hi = mid - 1;
21+
}
22+
}
23+
return citations.length - lo;
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)