C# solution, le sigh. 557ms. C# is much slower.


  • 1
    D
        public class Solution {
        public int CountPrimes(int n) {
            System.Collections.BitArray maps = new System.Collections.BitArray(n, true);
            int count=0;
            if (n <= 1){
                return 0;
            }
            for(int i=2; i < n; i++){
                if (maps[i]){
                    count++;
                }
                for (int j = 2 ; i * j < n ;j++ ){
                    maps[i*j] = false;
                }
            }
            return count;
        }
    }

Log in to reply
 

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