[LeetCode] Sqrt(x)
2014-07-21 21:47
387 查看
Implement
Compute and return the square root of x.
百度百科里,牛顿迭代解释:http://baike.baidu.com/view/643093.htm?fr=aladdin
已经证明,如果是连续的,并且待求的零点是孤立的,那么在零点周围存在一个区域,只要初始值位于这个邻近区域内,那么牛顿法必定收敛。
详细见此博客:http://blog.csdn.net/wumuzi520/article/details/7026808
int sqrt(int x).
Compute and return the square root of x.
百度百科里,牛顿迭代解释:http://baike.baidu.com/view/643093.htm?fr=aladdin
已经证明,如果是连续的,并且待求的零点是孤立的,那么在零点周围存在一个区域,只要初始值位于这个邻近区域内,那么牛顿法必定收敛。
详细见此博客:http://blog.csdn.net/wumuzi520/article/details/7026808
class Solution { public: int sqrt(int x) { double ans = x; while(abs(ans*ans-x)>0.0001) { ans = (ans+x/ans)/2; } return ans; } };
相关文章推荐
- Leetcode:69. Sqrt(x)
- LeetCode-Sqrt(x)
- LeetCode 69. Sqrt(x)
- LeetCode069 Sqrt(x)
- 72 leetcode - Sqrt(x)
- 【一天一道LeetCode】#69. Sqrt(x)
- LeetCode | 69. Sqrt(x)
- leetcode Sqrt(x) 求开方
- 【leetcode】69. Sqrt(x)(Python & C++)
- 数据结构与算法[LeetCode]——sqrt(x)
- LeetCode: Sqrt(x)
- LeetCode 69 Sqrt(x)
- leetcode [Sqrt(x)]
- LeetCode:Sqrt(x)
- leetcode:69. Sqrt(x)
- Sqrt(x) -- leetcode
- [leetcode]Sqrt(x)
- [LeetCode]--69. Sqrt(x)
- 【LeetCode】69. Sqrt(x) 解题报告
- leetcode之sqrt