BAEL-5004 Fixed overflow issues for Large numbers (#10899)
Co-authored-by: Remy Ohajinwa <remy.ohajinwa@interswitchgroup.com>
This commit is contained in:
parent
19129f3721
commit
940773966e
|
@ -12,7 +12,7 @@ public class BinarySearch {
|
||||||
|
|
||||||
while (low <= high) {
|
while (low <= high) {
|
||||||
|
|
||||||
int mid = (low + high) / 2;
|
int mid = low + ((high - low) / 2);
|
||||||
|
|
||||||
if (sortedArray[mid] < key) {
|
if (sortedArray[mid] < key) {
|
||||||
low = mid + 1;
|
low = mid + 1;
|
||||||
|
@ -28,7 +28,7 @@ public class BinarySearch {
|
||||||
|
|
||||||
public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
|
public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
|
||||||
|
|
||||||
int middle = (low + high) / 2;
|
int middle = low + ((high - low) / 2);
|
||||||
if (high < low) {
|
if (high < low) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue