classSolution:defsortColors(self, nums: List[int])->None:"""
Do not return anything, modify nums in-place instead.
"""
left =0
right =1for left inrange(len(nums)):for right inrange(left+1,len(nums)):if nums[left]> nums[right]:
nums[left], nums[right]= nums[right], nums[left]
classSolution:defsortColors(self, nums: List[int])->None:"""
Do not return anything, modify nums in-place instead.
"""#双指针iflen(nums)==1:return nums
left =0
right =0while left <len(nums):
right = left +1while right <len(nums):if nums[left]> nums[right]:
nums[left], nums[right]= nums[right], nums[left]
right +=1
left +=1
Leetcode75-颜色分类代码:class Solution: def sortColors(self, nums: List[int]) -> None: """ Do not return anything, modify nums in-place instead. """ left = 0 right = 1 for left in range(len(nums)):