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