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 5917fc2 commit a2f8d74Copy full SHA for a2f8d74
leetcode/medium/912_sort_an_array.md
@@ -109,3 +109,23 @@ class Solution:
109
110
return merge_sort(nums)
111
```
112
+
113
+## Bubble Sort
114
115
+- Runtime: O(N^2)
116
+- Space: O(1)
117
+- N = Number of elements in list
118
119
+Each time we perform a bubble sort, we are essential pushing the max value of the array to the back of the array.
120
121
+The advantage of bubble sort is the lack of memory or constant memory space.
122
123
+```
124
+class Solution:
125
+ def sortArray(self, nums: List[int]) -> List[int]:
126
+ for i in reversed(range(0, len(nums))):
127
+ for curr in range(0, i):
128
+ if nums[curr] > nums[curr+1]:
129
+ nums[curr], nums[curr+1] = nums[curr+1], nums[curr]
130
+ return nums
131
0 commit comments