class Solution {
public:
int mySqrt(int x) {
int low = 0, high = x;
if(x == 0 || x == 1) {
return x;
}
while(low < high) {
int mid = (low + high) / 2;
cout << mid << mid << endl;
if(x / mid == mid) { // 使用除而不是*是因为乘可能会超出范围
return mid;
}
if(x / mid > mid) {
low = mid + 1;
} else {
high = mid;
}
}
return high - 1;
}
};