文章作者:Tyan
博客:noahsnail.com ?|? CSDN ?|? 簡(jiǎn)書(shū)
1. Description
2. Solution
class Solution {
public:
bool isPerfectSquare(int num) {
int left = 0;
int right = num;
while(left <= right) {
long mid = (left + right) / 2;
long square = mid * mid;
if(square == num) {
return true;
}
if(square > num) {
right = mid - 1;
}
else {
left = mid + 1;
}
}
return false;
}
};