Skip to content

Commit f998645

Browse files
committed
wip: attempting insertion sort 24h 48h later to make sure I understand it -@iamserda
1 parent 2a27fb9 commit f998645

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import random
2+
3+
4+
class Solution:
5+
6+
def insertionSort(self, arr: list) -> list:
7+
if len(arr) < 2:
8+
return arr
9+
for i in range(1, len(arr)):
10+
j = i - 1
11+
while j >= 0 and arr[j] > arr[j+1]:
12+
13+
14+
sol = Solution()
15+
16+
arr = [10, 1, 20, 2, 30, 3, 4, 40, 5]
17+
assert sol.insertionSort(arr) == [1, 2, 3, 4, 5, 10, 20, 30, 40]
18+
19+
arr = [0, 4, 3, 2, 4, 0]
20+
assert sol.insertionSort(arr) == [0, 0, 2, 3, 4, 4]
21+
22+
arr = [1, 3, 5, 4, 2]
23+
assert sol.insertionSort(arr) == [1, 2, 3, 4, 5]

0 commit comments

Comments
 (0)