Update binary_search.py (#4856)

Take less time to calculate
This commit is contained in:
harshitkap00r 2021-10-27 09:55:48 +05:30 committed by GitHub
parent fe5c711ce6
commit ce9a139b56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,7 +51,7 @@ def bisect_left(
hi = len(sorted_collection)
while lo < hi:
mid = (lo + hi) // 2
mid = lo + (hi - lo) // 2
if sorted_collection[mid] < item:
lo = mid + 1
else:
@ -96,7 +96,7 @@ def bisect_right(
hi = len(sorted_collection)
while lo < hi:
mid = (lo + hi) // 2
mid = lo + (hi - lo) // 2
if sorted_collection[mid] <= item:
lo = mid + 1
else: