From 4f4569710d2015160436d4fa7fb66c8b154665a1 Mon Sep 17 00:00:00 2001 From: harshitkap00r <76745800+harshitkap00r@users.noreply.github.com> Date: Fri, 1 Oct 2021 23:31:08 +0530 Subject: [PATCH] Update binary_search.py Take less time to calculate --- searches/binary_search.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/searches/binary_search.py b/searches/binary_search.py index 0966cd8de857..88fee47157c6 100644 --- a/searches/binary_search.py +++ b/searches/binary_search.py @@ -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: