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
5 changes: 4 additions & 1 deletion searches/binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,13 @@
>>> binary_search([0, 5, 7, 10, 15], 6)
-1
"""
if list(sorted_collection) != sorted(sorted_collection):
if any(
sorted_collection[i] > sorted_collection[i + 1]
for i in range(len(sorted_collection) - 1)
):
raise ValueError("sorted_collection must be sorted in ascending order")
left = 0

Check failure on line 206 in searches/binary_search.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (invalid-syntax)

searches/binary_search.py:206:1: invalid-syntax: unindent does not match any outer indentation level
right = len(sorted_collection) - 1

Check failure on line 207 in searches/binary_search.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (invalid-syntax)

searches/binary_search.py:207:1: invalid-syntax: Unexpected indentation

while left <= right:
midpoint = left + (right - left) // 2
Expand Down
Loading