We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6bbb76c commit dcf35a3Copy full SHA for dcf35a3
0075M. Sort Colors.py
@@ -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