75. Sort Colors

class Solution(object):
    def sortColors(self, nums):
        """
        :type nums: List[int]
        :rtype: void Do not return anything, modify nums in-place instead.
        """
        zero, two,i= 0, len(nums)-1,0 
        while i<=two:
            if nums[i]==0:
                nums[zero],nums[i]=nums[i],nums[zero]
                zero+=1
                i+=1
            elif nums[i]==2:
                nums[two],nums[i]=nums[i],nums[two]
                two-=1
            else: i+=1
            

你可能感兴趣的:(75. Sort Colors)