[LeetCode][Python3] 204. Count Primes
2018. 11. 4. 19:15 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/count-primes/
My Solution :
class Solution:
def countPrimes(self, n):
"""
:type n: int
:rtype: int
"""
is_prime = [1]*n
for i in range(2, int(n**0.5)+1):
if is_prime[i]:
for j in range(i**2, n, i):
is_prime[j] = 0
return sum(is_prime[2:])
Comment :
에라토스테네스의 체 문제이다.
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 268. Missing Number (0) | 2018.11.04 |
---|---|
[LeetCode][Python3] 242. Valid Anagram (0) | 2018.11.04 |
[LeetCode][Python3] 237. Delete Node in a Linked List (0) | 2018.11.04 |
[LeetCode][Python3] 217. Contains Duplicate (0) | 2018.11.04 |
[LeetCode][Python3] 202. Happy Number (0) | 2018.11.04 |
[LeetCode][Python3] 191. Number of 1 Bits (0) | 2018.11.04 |
[LeetCode][Python3] 190. Reverse Bits (0) | 2018.11.04 |
[LeetCode][Python3] 189. Rotate Array (0) | 2018.11.03 |
최근에 달린 댓글 최근에 달린 댓글