Implement int sqrt(int x).
class Solution {
public:
int sqrt(int x) {
int min = 0;
int max = INT_MAX;
int mid;
while(max>min)
{
if(max-min==1) return min;
mid = (max+min)/2;
if(x/mid==mid) return mid; //mid*mid==x 会超出范围
else if(x/mid>mid)
min = mid;
else max = mid;
}
return mid;
}
};