-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsol75.py
More file actions
28 lines (25 loc) · 736 Bytes
/
sol75.py
File metadata and controls
28 lines (25 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from typing import List
class Solution75:
def sortColors(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
i = j = 0
x = 0
while i < len(nums):
while i < len(nums) and nums[i] == x:
i += 1
j = max(j, i + 1)
while j < len(nums):
if nums[j] == x:
temp = nums[i]
nums[i] = nums[j]
nums[j] = temp
j += 1
break
j += 1
if j == len(nums):
if nums[i] == x:
i += 1
x += 1
j = i + 1