To avoid overflow, so change the mid value (#237)
This commit is contained in:
parent
7c16c2b94e
commit
1ae937068c
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user