mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-09-28 21:45:27 +08:00
Fix exponential search for empty collections (#15362)
Co-authored-by: = <=>
This commit is contained in:
@@ -85,6 +85,8 @@ def exponential_search(sorted_collection: list[int], item: int) -> int:
|
||||
if list(sorted_collection) != sorted(sorted_collection):
|
||||
raise ValueError("sorted_collection must be sorted in ascending order")
|
||||
|
||||
if not sorted_collection:
|
||||
return -1
|
||||
if sorted_collection[0] == item:
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user