0367. Valid Perfect Square
Description
**Input:** num = 16
**Output:** true**Input:** num = 14
**Output:** falseac1: Newton method
class Solution {
public boolean isPerfectSquare(int num) {
long r = num;
while (r * r > num) {
r = (r + num / r) / 2;
}
return r * r == num;
}
}Last updated