-
Notifications
You must be signed in to change notification settings - Fork 72
/
Solution.java
37 lines (34 loc) · 919 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package g0201_0300.s0275_h_index_ii;
// #Medium #Array #Binary_Search #Binary_Search_II_Day_8
// #2022_07_06_Time_0_ms_(100.00%)_Space_52.9_MB_(13.67%)
public class Solution {
public int hIndex(int[] citations) {
int lo = 1;
int hi = 1000;
int ans = 0;
while (lo <= hi) {
int mid = (lo + hi) / 2;
int p = check(mid, citations);
if (citations.length - p >= mid) {
ans = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
return ans;
}
private int check(int v, int[] arr) {
int lo = 0;
int hi = arr.length - 1;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (arr[mid] < v) {
lo = mid + 1;
} else {
hi = mid - 1;
}
}
return lo;
}
}