일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Python Implementation
- Substring with Concatenation of All Words
- 시바견
- 43. Multiply Strings
- LeetCode
- concurrency
- shiba
- 운영체제
- Decorator
- attribute
- Python
- 315. Count of Smaller Numbers After Self
- kaggle
- 30. Substring with Concatenation of All Words
- 715. Range Module
- 파이썬
- 109. Convert Sorted List to Binary Search Tree
- Generator
- 컴퓨터의 구조
- Python Code
- Convert Sorted List to Binary Search Tree
- Class
- data science
- DWG
- iterator
- Regular Expression
- Protocol
- 프로그래머스
- t1
- 밴픽
Archives
- Today
- Total
Scribbling
LeetCode: 75. Sort Colors 본문
We already know that all the elements are in [0, 1, 2].
So, we count each element's frequencies.
class Solution:
def sortColors(self, nums: List[int]) -> None:
"""
Do not return anything, modify nums in-place instead.
"""
count = [0] * 3
for num in nums:
count[num] += 1
count[2] = count[1] + count[0]
count[1] = count[0]
for i in range(count[1]):
nums[i] = 0
for i in range(count[1], count[2]):
nums[i] = 1
for i in range(count[2], len(nums)):
nums[i] = 2
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 76. Minimum Window Substring (0) | 2021.09.30 |
---|---|
LeetCode: 77. Combinations (0) | 2021.09.28 |
LeetCode: 74. Search a 2D Matrix (0) | 2021.09.28 |
LeetCode: 73. Set Matrix Zeroes (0) | 2021.09.28 |
LeetCode: 72. Edit Distance (0) | 2021.09.26 |