import java.util.*;
public class Solution {
/**
*
* @param x int整型
* @return int整型
*/
public int mysqrt (int x) {
if(x == 1) {
return 1;
}
int left = 1, right = x / 2 ;
int mid = 1;
while(left <= right) {
mid = (left + right)/ 2;
// 不要写成mid*mid有可能会溢出
if (x / mid == mid) {
return mid;
} else if (x / mid < mid) {
right = mid - 1;
} else {
left = mid + 1;
}
}
// while结束条件一定是left <= end,所以返回end,一定不会是mid
return right;
}
}