题目:
解题思路:
二分查找
时间复杂度:
空间复杂度:
bool isPerfectSquare(int num) {
int l = 0, r = 50000;
while (l <= r) {
long long mid = (l + r) / 2;
if (num < mid * mid) {
r = mid - 1;
}
else if (num > mid*mid) {
l = mid + 1;
}
else return true;
}
return false;
}