-
12. Count PrimesProblem Solving 2022. 9. 4. 00:26728x90
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이 안 됨ㅠㅠ
흐앙
다른 사람 코드들 참고해서 푼 거라 나중에 다시 풀어봐야 할 듯
'Problem Solving' 카테고리의 다른 글
14. Summary Ranges (0) 2022.09.04 13. Single Number (0) 2022.09.04 11. 실패율 (0) 2022.09.01 10. 문자열 압축 (2) 2022.08.31 9. 문자열 다루기 기본 (0) 2022.08.30