public class TxTest {
public static void main(String[] args) {
int[] arrays = {-10, 1, 2, 3, 4, 5, 5};
fun1(arrays, -3, 3);
}
public static void fun1(int[] arrays, int start, int end) {
int startIndex = startBound(arrays, start);
int endIndex = endBound(arrays, end);
System.out.println("[" + startIndex + "," + endIndex + "]");
}
private static int startBound(int[] arrays, int key) {
int start = 0;
int last = arrays.length;
while (start < last) {
int mid = (start + last) / 2;
if (arrays[mid] >= key) {
last = mid;
} else {
start = mid + 1;
}
}
return start;
}
private static int endBound(int[] arrays, int key) {
int start = 0;
int last = arrays.length;
while (start < last) {
int mid = (start + last) / 2;
if (arrays[mid] <= key) {
start = mid + 1;
} else {
last = mid;
}
}
return start - 1;