method1
simple but not allow
public boolean isPerfectSquare(int num) {
int sqrt = (int) Math.sqrt(num);
return sqrt * sqrt == num;
}
method2
newto method
public boolean isPerfectSquare(int num) {
long x = num;
while (x * x > num) {
x = (x + num / x) >>> 1;
}
return x * x == num;
}
method3
binary search.