fork download
  1. # your code goes here
  2.  
  3. class Solution:
  4. def sortColors(self, nums):
  5. low, mid, high = 0, 0, len(nums) - 1
  6.  
  7. while mid <= high:
  8. if nums[mid] == 0:
  9. nums[low], nums[mid] = nums[mid], nums[low]
  10. low += 1
  11. mid += 1
  12. elif nums[mid] == 1:
  13. mid += 1
  14. else: # nums[mid] == 2
  15. nums[mid], nums[high] = nums[high], nums[mid]
  16. high -= 1
  17.  
Success #stdin #stdout 0.11s 14172KB
stdin
Standard input is empty
stdout
Standard output is empty