From 1ae937068c3b1bf0be969d74fdd02a635d5b3293 Mon Sep 17 00:00:00 2001 From: MX <76264890+xingxing-prog@users.noreply.github.com> Date: Sun, 8 May 2022 12:21:36 -0400 Subject: [PATCH] To avoid overflow, so change the mid value (#237) --- coding/python/binary_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coding/python/binary_search.py b/coding/python/binary_search.py index 168d10b..035959d 100644 --- a/coding/python/binary_search.py +++ b/coding/python/binary_search.py @@ -9,7 +9,7 @@ def binary_search(arr: List[int], lb: int, ub: int, target: int) -> int: A Binary Search Example which has O(log n) time complexity. """ if lb <= ub: - mid: int = ub + lb // 2 + mid: int = lb + (ub -lb)// 2 if arr[mid] == target: return mid elif arr[mid] < target: