Skip to content

Commit 6df7084

Browse files
author
deepshekhardas
committed
fix: raise ValueError on negative inputs in radix_sort
Fixes #14950
1 parent f5988cc commit 6df7084

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

sorts/radix_sort.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ def radix_sort(list_of_ints: list[int]) -> list[int]:
2121
True
2222
>>> radix_sort([1,100,10,1000]) == sorted([1,100,10,1000])
2323
True
24+
>>> radix_sort([-1, 2, -5, 0])
25+
Traceback (most recent call last):
26+
...
27+
ValueError: radix_sort() cannot sort negative numbers
2428
"""
29+
if any(i < 0 for i in list_of_ints):
30+
raise ValueError("radix_sort() cannot sort negative numbers")
2531
placement = 1
2632
max_digit = max(list_of_ints)
2733
while placement <= max_digit:

0 commit comments

Comments
 (0)