牛顿法
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)
本文共 306 字,大约阅读时间需要 1 分钟。
牛顿法
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