Skip to content

Commit 21171bf

Browse files
committed
May 17
1 parent b53ac12 commit 21171bf

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

2025-05-May-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
| May 14 | [3337. Total Characters in String After Transformations II](https://leetcode.com/problems/total-characters-in-string-after-transformations-ii/) | Hard | Unsolved |
2121
| May 15 | [2900. Longest Unequal Adjacent Groups Subsequence I](https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-i/) | Easy | Solved |
2222
| May 16 | [2901. Longest Unequal Adjacent Groups Subsequence II](https://leetcode.com/problems/longest-unequal-adjacent-groups-subsequence-ii/) | Medium | Unsolved |
23-
| May 17 | []() | | |
23+
| May 17 | [75. Sort Colors](https://leetcode.com/problems/sort-colors/) | Medium | Solved |
2424
| May 18 | []() | | |
2525
| May 19 | []() | | |
2626
| May 20 | []() | | |
@@ -41,5 +41,5 @@
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 4 | 4 | 0 |
44-
| Medium | 8 | 7 | 1 |
44+
| Medium | 9 | 7 | 2 |
4545
| Hard | 3 | 1 | 2 |
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution:
2+
def sortColors(self, nums: list[int]) -> None:
3+
left, right = 0, len(nums) - 1
4+
ptr = 0
5+
while ptr <= right:
6+
if nums[ptr] == 0:
7+
nums[left], nums[ptr] = nums[ptr], nums[left]
8+
left += 1
9+
ptr += 1
10+
elif nums[ptr] == 1:
11+
ptr += 1
12+
elif nums[ptr] == 2:
13+
nums[right], nums[ptr] = nums[ptr], nums[right]
14+
right -= 1
15+
16+
17+
def main():
18+
nums = [2, 0, 2, 1, 1, 0]
19+
Solution().sortColors(nums)
20+
assert nums == [0, 0, 1, 1, 2, 2]
21+
22+
nums = [2, 0, 1]
23+
Solution().sortColors(nums)
24+
assert nums == [0, 1, 2]
25+
26+
27+
if __name__ == '__main__':
28+
main()

0 commit comments

Comments
 (0)