还是考察在数组上的操作2换到最后,0换到最前面
class Solution(object):
def sortColors(self, nums):
"""
:type nums: List[int]
:rtype: void Do not return anything, modify nums in-place instead.
"""
p = 0
i = 0
q = len(nums) - 1
if q>0:
while i<=q:
if nums[i]==2:
nums[i],nums[q]=nums[q],nums[i]
q-=1
elif nums[i]==0:
nums[i],nums[p]=nums[p],nums[i]
p+=1
i+=1
else:
i+=1