Skip to content

Commit dcf35a3

Browse files
Create 0075M. Sort Colors.py
1 parent 6bbb76c commit dcf35a3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

0075M. Sort Colors.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#Runtime: 28 ms, faster than 91.21% of Python3 online submissions for Sort Colors.
2+
#Memory Usage: 14.1 MB, less than 75.60% of Python3 online submissions for Sort Colors.
3+
4+
class Solution:
5+
def sortColors(self, nums: List[int]) -> None:
6+
"""
7+
Do not return anything, modify nums in-place instead.
8+
"""
9+
i = 0
10+
n_1 = nums.count(1)
11+
n_2 = nums.count(2)
12+
while i < len(nums):
13+
if nums[i] != 0:
14+
nums.pop(i)
15+
else:
16+
i += 1
17+
for j in range(n_1):
18+
nums.append(1)
19+
for j in range(n_2):
20+
nums.append(2)

0 commit comments

Comments
 (0)