일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Substring with Concatenation of All Words
- 프로그래머스
- data science
- LeetCode
- Generator
- shiba
- Regular Expression
- Python Code
- concurrency
- Convert Sorted List to Binary Search Tree
- t1
- Python
- iterator
- Class
- kaggle
- DWG
- 운영체제
- 컴퓨터의 구조
- attribute
- Python Implementation
- 109. Convert Sorted List to Binary Search Tree
- 43. Multiply Strings
- 시바견
- 315. Count of Smaller Numbers After Self
- 715. Range Module
- Protocol
- Decorator
- 파이썬
- 30. Substring with Concatenation of All Words
- 밴픽
Archives
- Today
- Total
Scribbling
LeetCode: 204. Count Primes 본문
"Eratosthenes Algorithm"을 사용한다.
class Solution:
def countPrimes(self, n: int) -> int:
if n <= 1:
return 0
isPrime = [True] * n
p = 2
while p * p <= n:
if isPrime[p]:
q = p * p
while q < n:
isPrime[q] = False
q += p
p += 1
ret = 0
for i in range(2, n):
if isPrime[i]:
ret += 1
return ret
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 210. Course Schedule II (0) | 2021.12.07 |
---|---|
LeetCode: 1011. Capacity To Ship Packages Within D Days (0) | 2021.12.06 |
LeetCode: 198. House Robber (0) | 2021.12.04 |
LeetCode: 179. Largest Number (0) | 2021.12.04 |
LeetCode: 172. Factorial Trailing Zeroes (0) | 2021.12.04 |