首页 > 技术文章 > Leetcode 69. Sqrt(x)

zywscq 2019-04-15 05:31 原文

牛顿法

class Solution:
    def mySqrt(self, x: int) -> int:
        if x == any([0, 1]):
            return x
        now = x / 2
        while 1:
            if now * now - float(x) < 1:
                 return int(now)
            now = (x + now * now) / (2 * now)

 

推荐阅读