Skip to content

Commit 86fdac9

Browse files
authored
Refactor mid calculation to prevent overflow
Refactor mid calculation to prevent overflow
1 parent cee38ed commit 86fdac9

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

pygorithm/searching/binary_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def search(_list, target):
3232
try:
3333
# you can also write while True condition
3434
while left <= right:
35-
mid = (left + right) // 2
35+
mid = left + (right - left) // 2
3636
if target == _list[mid]:
3737
return mid
3838
elif target < _list[mid]:

0 commit comments

Comments
 (0)