class Solution {
public:
bool isPerfectSquare(int num) {
int l=1;
int h=100000;
long long mid=l+(h-l)/2;
long long sq;
while(l<=h)
{
sq=mid*mid;
if(sq==num) return true;
if(sq<num) l=mid+1;
else h=mid-1;
mid=l+(h-l)/2;
}
return false;
}
};
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter