Leetcode75.颜色分类
https://leetcode-cn.com/problems/sort-colors/solution/yan-se-fen-lei-by-leetcode/
class Solution:
def sortColors(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
p1,p2 = 0,len(nums)-1
cur = 0
while cur<=p2:
if nums[cur] == 0:
nums[cur], nums[p1] = nums[p1], nums[cur]
p1 += 1
cur += 1
elif nums[cur] == 2:
nums[cur], nums[p2] = nums[p2], nums[cur]
p2 -= 1
else:
cur += 1