Can you find what's wrong with this code? getting Time limit exceeded


  • 0
    M

    I am getting Time Limit Exceeded - Last executed input:
    999983
    Does any one know what is wrong with my code?

    public class Solution {
        public int countPrimes(int n) {
            int count = 0;
            if(n <= 2){
                return 0;
            }
            boolean isPrime;
            for(int i=2; i < n; i++){
                isPrime = true;
                for(int j=2; j <= i/j; j++){
                    if(i % j == 0 && i != j){
                        isPrime = false;
                        break;
                    }
                }
                if(isPrime){
                    count++;
                }
            }
            return count;
        }
    }
    

    Thanks!


  • 0
    J

    same problem :( do you find any solution?


  • 0
    M

    @juran321 : Not yet.


Log in to reply
 

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