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