class Solution {
public int mySqrt(int x) {
int left=0;
int right=x-1;
int ans=-1;
if (x == 0 || x==1) return x;
while (left<=right){
int mid=(left+right)>>>1;
if ((long)mid*mid<= x) {
ans = mid;
left=mid+1;
}
else{
right=mid-1;
}
}
return ans;
}
}