算法--快排
核心:对于增序,目标值target左边元素的值都小于target,右边元素的值都大于target,然后使用递归的方式使得每一位元素都有序
def quicksort(nums:List[int], left:int, right:int):
if left < right:
# 为了方便,一般以左边元素为target,更好地方式的随机位置
target = nums[left]
low, high = left, right
while low < high:
while target <= nums[high] and low < high:
high -= 1
nums[low] = nums[high]
while target >= nums[low] and low < high:
low += 1
nums[high] = nums[low]
nums[low] = target
quicksort(nums, left, low - 1)
quicksort(nums, low + 1, right)