20 lines
No EOL
460 B
Python
20 lines
No EOL
460 B
Python
def mergeSort(lst: list) -> list:
|
|
if len(lst) > 1:
|
|
mid = len(lst) // 2
|
|
left = lst[:mid]
|
|
right = lst[mid:]
|
|
|
|
mergeSort(left)
|
|
mergeSort(right)
|
|
|
|
i = j = k = 0
|
|
|
|
while i < len(left) and j < len(right):
|
|
if left[i] <= right[j]:
|
|
lst[k] = left[i]
|
|
i += 1
|
|
else:
|
|
lst[k] = right[j]
|
|
|
|
|
|
print(mergeSort([3,5,2,1])) |