We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 06fcd14 commit c1994c0Copy full SHA for c1994c0
sorts/cyclic_sort.py
@@ -24,16 +24,13 @@ def cyclic_sort(nums: list) -> list:
24
[1, 2, 3, 4, 5]
25
>>> cyclic_sort([])
26
[]
27
- >>> cyclic_sort([-2, -5, -45])
28
- [-45, -5, -2]
29
"""
30
31
# Perform cyclic sort
32
i = 0
33
while i < len(nums):
34
# Calculate the correct index for the current element
35
correct_index = nums[i] - 1
36
-
37
# If the current element is not at its correct position,
38
# swap it with the element at its correct index
39
if nums[i] != nums[correct_index]:
0 commit comments