


class Solution(object):
def sortColors(self, nums):
low = 0
mid = 0
high = len(nums) - 1
while mid <= high:
if nums[mid] == 0:
# Found a red (0), move it to the left section
nums[mid], nums[low] = nums[low], nums[mid]
low += 1
mid += 1
elif nums[mid] == 1:
# Found a white (1), it's already in correct position
mid += 1
else: # nums[mid] == 2
# Found a blue (2), move it to the right section
nums[mid], nums[high] = nums[high], nums[mid]
high -= 1
# Don't increment mid as the swapped element needs checking
IE260_20210342_SeungyunShin.pptx
