用牛顿法求平方根,早有耳闻
class Solution(object):
def mySqrt(self, x):
def diedai(x0,a):
return (x0*x0+a)/
2/x0
x0=a=float(x)
if x==
0:
return
0
while int(x0)!=int(diedai(x0,a)):
x0=diedai(x0,a)
return int(x0)