```
class Solution(object):
def myPow(self, x, n):
if n == 0:
return 1
if n == 1:
return x
half = self.myPow(x, abs(n) / 2)
return half * half * self.myPow(x, n % 2) if n > 0 else 1 / (half * half * self.myPow(x, n % 2))
```