[Leetcode] Sqrt(x)
生活随笔
收集整理的這篇文章主要介紹了
[Leetcode] Sqrt(x)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Implement?int sqrt(int x).
Compute and return the square root of?x.
牛頓迭代法, 碉堡了。
class Solution { public:int sqrt(int x) {double ans = x;while (abs(ans * ans - x) > 0.0001) {ans = (ans + x / ans) / 2;}return (int)ans;} };?
總結
以上是生活随笔為你收集整理的[Leetcode] Sqrt(x)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: URAL 1029
- 下一篇: CSS3:linear-gradient