forked from onlybooks/python-algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path63-1.py
More file actions
17 lines (14 loc) · 484 Bytes
/
63-1.py
File metadata and controls
17 lines (14 loc) · 484 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from typing import List
class Solution:
def sortColors(self, nums: List[int]) -> None:
red, white, blue = 0, 0, len(nums)
while white < blue:
if nums[white] < 1:
nums[red], nums[white] = nums[white], nums[red]
white += 1
red += 1
elif nums[white] > 1:
blue -= 1
nums[white], nums[blue] = nums[blue], nums[white]
else:
white += 1