-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path75.py
More file actions
29 lines (27 loc) · 1.03 KB
/
75.py
File metadata and controls
29 lines (27 loc) · 1.03 KB
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
28
29
__________________________________________________________________________________________________
sample 24 ms submission
class Solution:
def sortColors(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
nums.sort()
__________________________________________________________________________________________________
sample 12912 kb submission
class Solution:
def sortColors(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
low, mid, high = 0, 0, len(nums) - 1
while mid <= high:
if nums[mid] == 0:
nums[low], nums[mid] = nums[mid], nums[low]
low += 1
mid += 1
elif nums[mid] == 2:
nums[high], nums[mid] = nums[mid], nums[high]
high -= 1
else:
mid += 1
__________________________________________________________________________________________________