Implementint sqrt(int x).
Compute and return the square root of x.
public class Solution {
public int mySqrt(int x) { // 用二分法解决
if(x<=0)
return 0;
int begin = 1;
int end = x;
int mid = 0;
while(begin<=end)
{
mid = (begin + end)>>1;
if(mid==x/mid)
return mid;
else if(mid<x/mid)
begin = mid +1;
else if(mid>x/mid)
end = mid -1;
}
return end; //为什么返回的是end???
}
}