简直蛋疼的一道题目…
class Solution {
public:
int mySqrt(int x) {
int left=1,right=x/2;
int mid;
if(x<2) return x;
while(left<=right){
int midV=(left+right)/2;
if(x/midV > midV){
left=midV+1;
mid=midV;
}
else if(x/midV < midV){
right=midV-1;
}
else return midV;
}
return mid;
}
};