Skip to content

Commit c6f9d7e

Browse files
Add files via upload
1 parent f7bba7d commit c6f9d7e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Sort Colors/Sort Colors.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# 48ms 39.41%
2+
class Solution:
3+
def sortColors(self, nums):
4+
"""
5+
:type nums: List[int]
6+
:rtype: void Do not return anything, modify nums in-place instead.
7+
"""
8+
index, left, right = 0, 0, len(nums) - 1
9+
while index <= right:
10+
if nums[index] is 0 and index != left:
11+
nums[index], nums[left] = nums[left], nums[index]
12+
left += 1
13+
elif nums[index] is 2 and index != right:
14+
nums[index], nums[right] = nums[right], nums[index]
15+
right -= 1
16+
else:
17+
index += 1

0 commit comments

Comments
 (0)