Commit 171ddaf
authored
⚡️ Speed up function
Here’s a much faster and more efficient implementation using Python’s built-in sorting, which internally uses Timsort (much faster than bubble sort).
Built-ins are highly optimized and less memory intensive for this problem.
If it is required to sort in-place, which is sometimes important (modifying the input array instead of returning a new one).
**Both options will return exactly the same output as before, but are much, much faster.**
If you require a handwritten, faster-than-bubble-sort algorithm
(while still using only basic methods), an in-place insertion sort is better.
But the previous two methods using `.sort()` or `sorted()` are preferred for both performance and simplicity.sorter by 289%1 parent 5aab3b8 commit 171ddaf
1 file changed
+8
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
0 commit comments