update 3637 mod solution
All checks were successful
Binary Search Test / test (push) Successful in 6s
All checks were successful
Binary Search Test / test (push) Successful in 6s
This commit is contained in:
@@ -8,13 +8,10 @@ public class BinarySearch3637 {
|
||||
public static void main(String[] args) {
|
||||
IntList a = new IntList();
|
||||
int x = Integer.parseInt(args[0]);
|
||||
|
||||
int n = args.length;
|
||||
|
||||
for (int i = 1; i < n; i++) {
|
||||
a.put(Integer.parseInt(args[i]));
|
||||
}
|
||||
|
||||
System.out.println(rightBound(x, a) - leftBound(x, a));
|
||||
}
|
||||
|
||||
@@ -23,13 +20,13 @@ public class BinarySearch3637 {
|
||||
high = a.getLength() - 1;
|
||||
while (low <= high) {
|
||||
int mid = low + (high - low) / 2;
|
||||
if (a.get(mid) >= x) {
|
||||
high = mid - 1;
|
||||
} else {
|
||||
if (a.get(mid) > x) {
|
||||
low = mid + 1;
|
||||
} else {
|
||||
high = mid - 1;
|
||||
}
|
||||
}
|
||||
return low;
|
||||
return high + 1;
|
||||
}
|
||||
|
||||
static int rightBound(int x, IntList a) {
|
||||
@@ -37,13 +34,13 @@ public class BinarySearch3637 {
|
||||
high = a.getLength() - 1;
|
||||
while (low <= high) {
|
||||
int mid = low + (high - low) / 2;
|
||||
if (a.get(mid) <= x) {
|
||||
if (a.get(mid) >= x) {
|
||||
low = mid + 1;
|
||||
} else {
|
||||
high = mid - 1;
|
||||
}
|
||||
}
|
||||
return low;
|
||||
return high + 1;
|
||||
}
|
||||
|
||||
static int searchIterativeDecreasing(int x, IntList a) {
|
||||
|
||||
Reference in New Issue
Block a user