Leetcode 69. Sqrt(x)

牛顿法

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)
原文地址:https://www.cnblogs.com/zywscq/p/10708524.html