Sunday, December 17, 2017

69. Sqrt(x)

Newton method:

class Solution:
    def mySqrt(self, x):
        """
        :type x: int
        :rtype: int
        """
        xi = x
        while xi*xi > x:
            xi = int((xi+x/xi)/2)
        return xi

No comments:

Post a Comment