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
原题链接:https://leetcode-cn.com/problems/sqrtx/
解题思路:
/** * @param {number} x * @return {number} */ var mySqrt = function (x) { function sqrt(x0) { // 当遇到第一个x0 * x0 <= x的值时,表示已经得到最接近的结果,将x0的整数部分返回即可 // 用Math.floor将x0*x0向下取整 // 避免例如TestCase: 5,会出现x0 * x0=5.000000000000001,造成死循环 if (Math.floor(x0 * x0) <= x) { return Math.floor(x0); } // 套用分析得到的迭代公式,计算出新的x0 x0 = (x0 + x / x0) / 2; return sqrt(x0); } return sqrt(x); };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
原题链接:https://leetcode-cn.com/problems/sqrtx/
解题思路:
The text was updated successfully, but these errors were encountered: