Damn ! I posted the wrong algo previously! Folks, look into this one. Gives outOfBound beyond 36449.


  • 0
    S

    public class Solution {
    public int countPrimes(int num)
    {
    int counter =0 ;
    boolean b[] = new boolean[num+1];

    	for(int i = 2; i < num; i++)
    	{
    		if(b[i] == false)
    		{
    			counter++;
    		{
    			for(int j = i*i; j<num; j =j+i )
    			{
    				b[j] = true;
    			}
    		}
    	}
    	}
    	
    	return counter;
    	
    }
    

    }


Log in to reply
 

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