您的位置:首页 > 其它

Leetcode 69. Sqrt(x)

2017-01-26 12:23 423 查看
public class Solution {
public int mySqrt(int x) {
long low = 0, high = x;
while (low + 1 < high) {
long mid = low + (high-low)/2;
if (mid * mid > x) high = mid;
else low = mid;
}
if (high * high <= x) return (int) high;
return (int) low;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: