LeetCode – Count Primes (Java)
Count the number of prime numbers less than a non-negative number, n Java Solution 1 This solution exceeds time limit. public int countPrimes(int n) { n = n-1; ArrayList<Integer> primes = new ArrayList<Integer>(); if(n<=1) return 0; if(n==2) return 1; if(n==3) return 2; primes.add(2); primes.add(3); for(int i=4; i<=n; i++){ boolean isPrime = … Read more