Skip to content

Commit 13ee9fb

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent b988168 commit 13ee9fb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

searches/binary_search.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ def binary_search(sorted_collection: list[int], item: int) -> int:
214214
midpoint = left + (right - left) // 2
215215
current_item = sorted_collection[midpoint]
216216
if current_item == item:
217-
result = midpoint # Found the item, but continue to find leftmost occurrence
217+
result = (
218+
midpoint # Found the item, but continue to find leftmost occurrence
219+
)
218220
right = midpoint - 1 # Look for more occurrences on the left
219221
elif item < current_item:
220222
right = midpoint - 1
@@ -284,7 +286,7 @@ def binary_search_by_recursion(
284286
right = len(sorted_collection) - 1
285287
if list(sorted_collection) != sorted(sorted_collection):
286288
raise ValueError("sorted_collection must be sorted in ascending order")
287-
289+
288290
# Helper function for the binary search
289291
def _binary_search_recursive(left_idx: int, right_idx: int) -> int:
290292
if right_idx < left_idx:
@@ -302,7 +304,7 @@ def _binary_search_recursive(left_idx: int, right_idx: int) -> int:
302304
return _binary_search_recursive(left_idx, midpoint - 1)
303305
else:
304306
return _binary_search_recursive(midpoint + 1, right_idx)
305-
307+
306308
return _binary_search_recursive(left, right)
307309

308310

0 commit comments

Comments
 (0)