题目:
题解:
Go
func mySqrt(x int) int {
if x == 0 {
return 0
}
C, x0 := float64(x), float64(x)
for {
xi := 0.5 * (x0 + C/x0)
if math.Abs(x0 - xi) < 1e-7 {
break
}
x0 = xi
}
return int(x0)
}