#countprimes
Explore tagged Tumblr posts
arifinfrds-blog · 2 years ago
Photo
Tumblr media
Leetcode - Count Primes using both Brute Force (slide 1) and Sieve of Eratosthenes solution (slide 2) (optimal) #arifinfrds #leetcode #leetcodesolution #datastructuresandalgorithms #programmer #softwarengineer #swiftprogramming #softwaredeveloper #countprimes #sieveoferatosthenes https://www.instagram.com/p/Cnk-CehS9x4/?igshid=NGJjMDIxMWI=
1 note · View note
kagaya25 · 6 years ago
Text
Leetcode Problem#204. Count Primes
Leetcode Problem#204. Count Primes
Count the number of prime numbers less than a non-negative number, n.
Example:
Input: 10 Output: 4 Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.
Solution:
class Solution(object): # @param {integer} n # @return {integer} def countPrimes(self, n): """ :type n: int :rtype: int """ if n < 3: return 0 primes = [True] * n primes[0] = primes[1] =…
View On WordPress
0 notes