Thank you for sharing. The solution shared can pass both of my local test and LeetCode online test.

The following is my solution. However, it cannot pass leetcode online test. It failed at the case of (8.88023, 3). It's a Runtime Error. And I have no idea why. I will appreciate if someone can share some ideas so I can figure it out.

{

```
def power(self, x, n):
if x == 0:
return 0
if n == 0:
return 1
result = self.power(x, n//2)
if n % 2 == 0:
return result * result
else:
return result * result * x
def pow(self, x, n):
if n > 0:
return self.power(x, n)
else:
return 1/self.power(x, n)
```

}

I also found a solution somewhere over the web. Please see the following. It can pass leetcode test cases. However, it cannot pass my local test case. The test case is simply the same as the above (8.88023, 3).

{

```
def pow(self, x, n):
if n == 0:
return 1.0
elif n < 0:
return 1 / self.pow(x, -n)
elif n % 2:
return self.pow(x*x,n/2)*x
else:
return self.pow(x*x,n/2)
```

}