Skip to content

Commit 1ae9370

Browse files
To avoid overflow, so change the mid value (bregman-arie#237)
1 parent 7c16c2b commit 1ae9370

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

coding/python/binary_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def binary_search(arr: List[int], lb: int, ub: int, target: int) -> int:
99
A Binary Search Example which has O(log n) time complexity.
1010
"""
1111
if lb <= ub:
12-
mid: int = ub + lb // 2
12+
mid: int = lb + (ub -lb)// 2
1313
if arr[mid] == target:
1414
return mid
1515
elif arr[mid] < target:

0 commit comments

Comments
 (0)