class Solution: def sortColors(self, nums: List[int]) -> None: """ Do not return anything, modify nums in-place instead. """ l, r = 0, len(nums) - 1 j = 0 while j < len(nums): if nums[j] == 0 and j >= l: nums[l], nums[j] = nums[j], nums[l] l += 1 elif nums[j] == 2 and j <= r: nums[r], nums[j] = nums[j], nums[r] r -= 1 else: j += 1 if not l<r: break