classSolution: defmyPow(self, x: float, n: int) -> float: # check if n is negative if n < 0: x = 1/x n = -n # We solve the positive power here: power = 1 current_product = x while n > 0: # if n is odd number, we need to time x one more time if n%2 : power = power * current_product current_product = current_product * current_product n = n//2 return power