일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- iterator
- data science
- Python
- 30. Substring with Concatenation of All Words
- 컴퓨터의 구조
- Python Implementation
- Protocol
- 315. Count of Smaller Numbers After Self
- concurrency
- 파이썬
- Regular Expression
- 109. Convert Sorted List to Binary Search Tree
- attribute
- kaggle
- Generator
- 운영체제
- DWG
- Decorator
- Class
- Substring with Concatenation of All Words
- 밴픽
- Python Code
- LeetCode
- 43. Multiply Strings
- t1
- Convert Sorted List to Binary Search Tree
- 시바견
- 프로그래머스
- 715. Range Module
- shiba
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 |