class Solution {
public boolean isPerfectSquare(int num) {
int lo = 1, hi = num;
while (lo < hi) {
int mid = lo - (lo - hi) / 2;
long temp = (long) mid * mid;
if (temp == num) return true;
else if (temp < num) lo = mid + 1;
else hi = mid - 1;
}
return lo * lo == num;
}
}