Typical binary search.. but take care of data overflow if you are using C++
class Solution {
public:
bool isPerfectSquare(int num) {
if(num < ) return false;
if(num < ) return true; long long i = , j = num - ;
while(i <= j)
{
long long mid = (i + j) / ;
long long r = mid * mid; if(r == num) return true;
if(r < num) i = mid + ;
else j = mid - ;
}
return false;
}
};