Monday, March 12, 2018

Beat 100% of python3 submissions

Yes! I did it.
Here is simple code that  gives me  performance  described on picture above.


class powxy:
    def pow(self, x, n):
        if n == 0.0:
            return 1
        if n < 0:
            n = -n
            x = 1/x
        if n % 2 == 0:
            return self.pow(x*x, int(n/2))
        return x*self.pow(x*x, int(n/2))

No comments:

Post a Comment