Skip to content

Commit ce9a139

Browse files
Update binary_search.py (TheAlgorithms#4856)
Take less time to calculate
1 parent fe5c711 commit ce9a139

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

searches/binary_search.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def bisect_left(
5151
hi = len(sorted_collection)
5252

5353
while lo < hi:
54-
mid = (lo + hi) // 2
54+
mid = lo + (hi - lo) // 2
5555
if sorted_collection[mid] < item:
5656
lo = mid + 1
5757
else:
@@ -96,7 +96,7 @@ def bisect_right(
9696
hi = len(sorted_collection)
9797

9898
while lo < hi:
99-
mid = (lo + hi) // 2
99+
mid = lo + (hi - lo) // 2
100100
if sorted_collection[mid] <= item:
101101
lo = mid + 1
102102
else:

0 commit comments

Comments
 (0)