```
public boolean isPerfectSquare(int num) {
if (num == 0) return true;
int start = 1;
int end = num;
while (start < end - 1) {
int mid = start + (end - start) / 2;
if (mid == num / mid && num % mid == 0) return true;
if (mid > num / mid) {
end = mid;
} else {
start = mid;
}
}
if ((num / start == start && num % start == 0) || (num % end == 0 && num / end == end)) return true;
else return false;
}
```