From 940773966e77d6a83a91acf0455a644e8553a731 Mon Sep 17 00:00:00 2001 From: Remy Ohajinwa Date: Thu, 17 Jun 2021 03:10:33 +0100 Subject: [PATCH] BAEL-5004 Fixed overflow issues for Large numbers (#10899) Co-authored-by: Remy Ohajinwa --- .../com/baeldung/algorithms/binarysearch/BinarySearch.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/algorithms-searching/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java index 82aefe282b..078914595e 100644 --- a/algorithms-searching/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java +++ b/algorithms-searching/src/main/java/com/baeldung/algorithms/binarysearch/BinarySearch.java @@ -12,7 +12,7 @@ public class BinarySearch { while (low <= high) { - int mid = (low + high) / 2; + int mid = low + ((high - low) / 2); if (sortedArray[mid] < key) { low = mid + 1; @@ -28,7 +28,7 @@ public class BinarySearch { 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) { return -1; }