Skip to content

Commit 73a511a

Browse files
Update cyclic_sort.py
1 parent 4a02f78 commit 73a511a

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

sorts/cyclic_sort.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,13 @@ def cyclic_sort(nums: list[int]) -> list[int]:
2929
"""
3030

3131
# Perform cyclic sort
32-
index = 0
33-
while index < len(nums):
32+
for index in range(len(nums)):
3433
# Calculate the correct index for the current element
3534
correct_index = nums[index] - 1
3635
# If the current element is not at its correct position,
3736
# swap it with the element at its correct index
3837
if index != correct_index:
3938
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
4439

4540
return nums
4641

0 commit comments

Comments
 (0)