Question: 367. Valid Perfect Square
Intution:
Time Complexity:
Space Complexity:
Solution:
class Solution {
public boolean isPerfectSquare(int num) {
long low = 1;
long high = num;
while (low <= high) {
long mid = low + (high - low) / 2;
if (mid * mid == num) return true;
else if (mid * mid < num) low = mid + 1;
else high = mid - 1;
}
return high * high == num;
}
}