My 11ms(sometimes) Java solution comes from hint may help u


  • 0
    public class Solution {
        public int countPrimes(int n) {
    		if (n < 3)
    			return 0;
    		int count = n / 2;
    		boolean[] isPrime = new boolean[n];
    		for (int i = 3; i * i < n; i += 2) {
    			if (isPrime[i])
    				continue;
    			for (int j = i * i; j < n; j += 2 * i) {
    				if (!isPrime[j]) {
    					--count;
    					isPrime[j] = true;
    				}
    			}
    		}
    		return count;
        }
    }

  • 0
    B

    what does "int count = n / 2; "mean?


  • 0

    The count of odd.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.