Last active
July 14, 2022 10:25
-
-
Save Hasiy/e71da3172274e56b0ed6783d027d8ef6 to your computer and use it in GitHub Desktop.
QuickSort kotlin 快排
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun quickSort(list: List<Int>): List<Int> { | |
return if (list.size <= 1) list | |
else { | |
list.takeLast(list.lastIndex) | |
.partition { it < list[0] } //分隔操作(partition) | |
.run { quickSort(first) + list[0] + quickSort(second) } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment