public class Solution {
/**
*
* @param x int整型
* @return int整型
*/
public int mysqrt (int x) {
// write code here
//空间O(1)
if(x == 1){
return 1;
}
int left = 1, right = x;
while(right >= left){
int mid = (right - left) / 2 +left;
if(mid <= x / mid && (mid + 1) > x / (mid +1)){
return mid;
}
if(mid > x /mid){
right = mid -1;
}else{
left = mid +1;
}
}
return 0;
}
}