From e80d248e65d20227d23098d354ca82f111d79967 Mon Sep 17 00:00:00 2001 From: Du YuanChao Date: Tue, 8 Oct 2019 16:25:00 +0800 Subject: [PATCH] optimization (#1303) --- sorts/selection_sort.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sorts/selection_sort.py b/sorts/selection_sort.py index 43ad26a7b..6a9c063d3 100644 --- a/sorts/selection_sort.py +++ b/sorts/selection_sort.py @@ -35,7 +35,8 @@ def selection_sort(collection): for k in range(i + 1, length): if collection[k] < collection[least]: least = k - collection[least], collection[i] = (collection[i], collection[least]) + if least != i: + collection[least], collection[i] = (collection[i], collection[least]) return collection