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 4a02f78 commit 73a511aCopy full SHA for 73a511a
sorts/cyclic_sort.py
@@ -29,18 +29,13 @@ def cyclic_sort(nums: list[int]) -> list[int]:
29
"""
30
31
# Perform cyclic sort
32
- index = 0
33
- while index < len(nums):
+ for index in range(len(nums)):
34
# Calculate the correct index for the current element
35
correct_index = nums[index] - 1
36
# If the current element is not at its correct position,
37
# swap it with the element at its correct index
38
if index != correct_index:
39
nums[index], nums[correct_index] = nums[correct_index], nums[index]
40
- else:
41
- # If the current element is already in its correct position,
42
- # move to the next element
43
- index += 1
44
45
return nums
46
0 commit comments