Skip to content

Instantly share code, notes, and snippets.

@Hasiy
Last active July 14, 2022 10:25
Show Gist options
  • Save Hasiy/e71da3172274e56b0ed6783d027d8ef6 to your computer and use it in GitHub Desktop.
Save Hasiy/e71da3172274e56b0ed6783d027d8ef6 to your computer and use it in GitHub Desktop.
QuickSort kotlin 快排
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