From b48738c671b865a8e89c6e3d616652f4ec466786 Mon Sep 17 00:00:00 2001 From: shellhub Date: Tue, 8 Oct 2019 10:45:30 +0800 Subject: [PATCH] optimization --- 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 43ad26a7bf27..6a9c063d3364 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