public int mySqrt(int x){
if (x==1){return 1;}
if (x==0){return 0;}
int left = 1, right = x/2;
while (left < right){
int mid = left + ((right - left) >> 1);
if (mid > x/mid){
right = mid - 1;
}else {
left = mid;
}
}
return left;
}
[算法系列] x的平方根——二分查找法(Java)
最新推荐文章于 2024-11-06 11:05:01 发布