Skip to content

Commit

Permalink
solved: practicing selection sort -@iamserda
Browse files Browse the repository at this point in the history
  • Loading branch information
iamserda committed Feb 18, 2025
1 parent c695f01 commit a3916af
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion neetcodeio/algostructybeginners/Lv3-Sorting/selection_sort.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
class Solution:

def selection_sort(self, arr: list) -> list:
pass
for i in range(len(arr)):
# where to place the next smallest value
min_index = i

for j in range(i, len(arr)):
# find the index of the smallest value
if arr[j] < arr[min_index]:
min_index = j
if min_index != i:
# swap the value at i with the value at min_index
arr[i], arr[min_index] = arr[min_index], arr[i]


sol = Solution()
Expand Down

0 comments on commit a3916af

Please sign in to comment.