Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions searches/binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,18 @@
raise ValueError("sorted_collection must be sorted in ascending order")
left = 0
right = len(sorted_collection) - 1

result = -1

Check failure on line 204 in searches/binary_search.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (W291)

searches/binary_search.py:204:16: W291 Trailing whitespace help: Remove trailing whitespace
while left <= right:
midpoint = left + (right - left) // 2
current_item = sorted_collection[midpoint]
if current_item == item:
return midpoint
result = midpoint
right = midpoint - 1
elif item < current_item:
right = midpoint - 1
else:
left = midpoint + 1
return -1
return result

Check failure on line 215 in searches/binary_search.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (W291)

searches/binary_search.py:215:18: W291 Trailing whitespace help: Remove trailing whitespace


def binary_search_std_lib(sorted_collection: list[int], item: int) -> int:
Expand Down
Loading