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