We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
可以采用二分法,获取最大,最小值,求他们的中间值的平方是否大于目标值,等于就直接返回,不等于则继续折半求中间值的平方直到接近目标值为止。
var mySqrt = function(x) { let l = 0, h = x, p = x / 2, lp = p; if(x === 1 || x === 0) return x; do{ if(Math.pow(p,2) > x){ h = p; }else if(Math.pow(p,2) < x){ l = p; }else{ return Math.floor(p); } lp = p; p = (l + h) / 2; }while(Math.abs(p - lp) >= Number.EPSILON); return Math.floor(p); };
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: