leetcode Count Primes

leetcode Count Primes

Description:

Count the number of prime numbers less than a non-negative number, n.

题目地址 : leetcode Count Primes 

思路:

朴素的判断必定超时,我们每次判断一个数是素数的时候,就将它的倍数标记为非素数即可。

下面附上c++  python 和 java代码

Code

c++

 

Java

 

 

Python

 

更多题解可以查看: https://www.hrwhisper.me/leetcode-algorithm-solution/

本博客若无特殊说明则由 hrwhisper 原创发布
转载请点名出处:细语呢喃 > leetcode Count Primes
本文地址:https://www.hrwhisper.me/leetcode-count-primes/

您的支持将鼓励我继续创作!

Leetcode , , , . permalink.

2 thoughts on “leetcode Count Primes

Leave a Reply

Your email address will not be published. Required fields are marked *