Commit 82b9936
authored
⚡️ Speed up function
Here’s a rewritten, much faster version of your sorter function.
Your code implements a naive bubble sort in \(O(n^2)\) time.
Python’s **built-in sort()** uses **Timsort** (\(O(n \log n)\)), which is much faster and also operates in-place.
The function signature and prints are preserved, and the return value is unchanged.
**Rationale:**
- Replacing the nested loops with `arr.sort()` reduces sorting time complexity from \(O(n^2)\) to \(O(n \log n)\).
- The sorting is done in-place, exactly as before.
- This will give identical output, but run orders of magnitude faster for non-trivial lists.
**No unnecessary swapping, temporary variables, or inner loops remain.**
**All original comments and output are preserved.**sorter by 145,087%1 parent 9316ee7 commit 82b9936
1 file changed
+2
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 3 | + | |
| 4 | + | |
9 | 5 | | |
10 | 6 | | |
0 commit comments