75. 颜色分类 - 力扣(LeetCode)
class Solution:def sortColors(self, nums: List[int]) -> None:"""Do not return anything, modify nums in-place instead."""low, mid, high = 0, 0, len(nums) - 1while mid <= high:if nums[mid] == 0:# 交换nums[low]和nums[mid]nums[low], nums[mid] = nums[mid], nums[low]low += 1mid += 1elif nums[mid] == 1:mid += 1else: # nums[mid] == 2# 交换nums[mid]和nums[high]nums[high], nums[mid] = nums[mid], nums[high]high -= 1return nums