Problem Solving
12. Count Primes
굥깡
2022. 9. 4. 00:26
728x90
https://leetcode.com/problems/count-primes/
Count Primes - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
주어진 n 미만의 수 중에 소수의 개수를 세는 문제
class Solution:
def countPrimes(self, n: int) -> int:
t = [False,False]+[True]*(n-2)
for i in range(2, n):
if t[i] == False:
continue
for j in range(i * 2, n, i):
t[j] = False
return t.count(True)
이거 푸는 데 진짜 오래 걸렸음 소수를 셀 줄 몰라서가 아니야... 자꾸 시간 초과 걸려서 Accept이 안 됨ㅠㅠ
흐앙
다른 사람 코드들 참고해서 푼 거라 나중에 다시 풀어봐야 할 듯