Simple but worst Java Solution


  • 1
    public boolean isPerfectSquare(int num) {
            if(num==1) return true;
            long i=2;
            while(i*i<=num && (i*i<Integer.MAX_VALUE)){
                while(num%(i*i)==0)
                    num/=i*i;
                if(num==1) return true;
                i++;
            }
            return false;
        }
    

Log in to reply
 

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