There was an error while loading. Please reload this page.
1 parent 5f12ba1 commit fd5d764Copy full SHA for fd5d764
1 file changed
sorts/cyclic_sort.py
@@ -52,12 +52,14 @@ def cyclic_sort(nums: list[int]) -> list[int]:
52
53
# Check for duplicates
54
if len(set(nums)) != n:
55
- raise ValueError(f"All numbers must be unique, got {nums}")
+ msg = f"All numbers must be unique, got {nums}"
56
+ raise ValueError(msg)
57
58
# Check if all numbers are in range 1 to n
59
for num in nums:
60
if num < 1 or num > n:
- raise ValueError(f"All numbers must be in range 1 to {n}, got {num}")
61
+ msg = f"All numbers must be in range 1 to {n}, got {num}"
62
63
64
# Perform cyclic sort
65
index = 0
0 commit comments