int mySqrt(int x) {
int left = 1;
int right = x / 2;
int mid = 0;
if(x == 0||x==1)
return x;
while(left + 1<right)
{
mid = left + (right - mid)/2;
if(mid<=x/mid)
left = mid;
else
right = mid - 1;
}
return right <= x/right ? right : left;
}
ps 这个题 mid <= x/mid 这个是为了防止int 溢出