标签:sqrt
Implement int sqrt(int x)
.
Compute and return the square root of x.
int mySqrt(int x) {
if(x<=1)
return x;
int left=1,right=x;
while(left<=right){
int mid=left+(right-left)/2;
int re=x/mid;
if(mid==re)
return mid;
else if(mid<re)
left=mid+1;
else
right=mid-1;
}
return right;
}
标签:sqrt
原文地址:http://searchcoding.blog.51cto.com/1335412/1695034