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 5ef8b6a commit 937173cCopy full SHA for 937173c
sorts/bubble_sort_recursive.py
@@ -1,7 +1,4 @@
1
-from typing import List
2
-
3
4
-def bubble_sort_recursive(arr: List[int]) -> List[int]:
+def bubble_sort_recursive(arr: list[int]) -> list[int]:
5
"""
6
Sorts a list of integers using the recursive Bubble Sort algorithm.
7
@@ -26,12 +23,10 @@ def bubble_sort_recursive(arr: List[int]) -> List[int]:
26
23
arr[i], arr[i + 1] = arr[i + 1], arr[i]
27
24
swapped = True
28
25
29
- # Base case: if no elements were swapped, the array is sorted
30
if not swapped:
31
return arr
32
33
- # Recursive call for the remaining unsorted part
34
- return bubble_sort_recursive(arr[:-1]) + [arr[-1]]
+ return [*bubble_sort_recursive(arr[:-1]), arr[-1]]
35
36
37
if __name__ == "__main__":
0 commit comments