class Solution {
public:
//左闭右闭
bool isPerfectSquare(int num) {
int left = 0;
int right = num;
while(left <= right)
{
int middle = left + ((right - left) >> 1);
if(num > long(middle) * long(middle))
{
left = middle + 1;
}
else if(num == long(middle) * long(middle))
{
return true;
}
else
{
right = middle - 1;
}
}
return false;
}
};
结果也是顺利通过