Update cyclic_sort.py

This commit is contained in:
Sharan Sukesh 2023-10-01 23:43:51 +05:30 committed by GitHub
parent 06fcd146bf
commit c1994c06e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,8 +24,6 @@ def cyclic_sort(nums: list) -> list:
[1, 2, 3, 4, 5]
>>> cyclic_sort([])
[]
>>> cyclic_sort([-2, -5, -45])
[-45, -5, -2]
"""
# Perform cyclic sort
@ -33,7 +31,6 @@ def cyclic_sort(nums: list) -> list:
while i < len(nums):
# Calculate the correct index for the current element
correct_index = nums[i] - 1
# If the current element is not at its correct position,
# swap it with the element at its correct index
if nums[i] != nums[correct_index]: