We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c695f01 commit a3916afCopy full SHA for a3916af
neetcodeio/algostructybeginners/Lv3-Sorting/selection_sort.py
@@ -1,7 +1,17 @@
1
class Solution:
2
3
def selection_sort(self, arr: list) -> list:
4
- pass
+ for i in range(len(arr)):
5
+ # where to place the next smallest value
6
+ min_index = i
7
+
8
+ for j in range(i, len(arr)):
9
+ # find the index of the smallest value
10
+ if arr[j] < arr[min_index]:
11
+ min_index = j
12
+ if min_index != i:
13
+ # swap the value at i with the value at min_index
14
+ arr[i], arr[min_index] = arr[min_index], arr[i]
15
16
17
sol = Solution()
0 commit comments