To avoid overflow, so change the mid value (#237)

This commit is contained in:
MX 2022-05-08 12:21:36 -04:00 committed by GitHub
parent 7c16c2b94e
commit 1ae937068c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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: