mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-11 17:19:48 +00:00
Update cyclic_sort.py
This commit is contained in:
parent
06fcd146bf
commit
c1994c06e9
@ -24,8 +24,6 @@ def cyclic_sort(nums: list) -> list:
|
|||||||
[1, 2, 3, 4, 5]
|
[1, 2, 3, 4, 5]
|
||||||
>>> cyclic_sort([])
|
>>> cyclic_sort([])
|
||||||
[]
|
[]
|
||||||
>>> cyclic_sort([-2, -5, -45])
|
|
||||||
[-45, -5, -2]
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Perform cyclic sort
|
# Perform cyclic sort
|
||||||
@ -33,7 +31,6 @@ def cyclic_sort(nums: list) -> list:
|
|||||||
while i < len(nums):
|
while i < len(nums):
|
||||||
# Calculate the correct index for the current element
|
# Calculate the correct index for the current element
|
||||||
correct_index = nums[i] - 1
|
correct_index = nums[i] - 1
|
||||||
|
|
||||||
# If the current element is not at its correct position,
|
# If the current element is not at its correct position,
|
||||||
# swap it with the element at its correct index
|
# swap it with the element at its correct index
|
||||||
if nums[i] != nums[correct_index]:
|
if nums[i] != nums[correct_index]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user