```
public class Solution {
public double MyPow(double x, int n) {
return Pow(n < 0 ? 1/x : x, n);
}
public double Pow(double x, int n) {
if(n==0) return 1;
else if(n==1 || n==-1) return x;
double half = Pow(x, n/2);
return half * half * (n%2==0 ? 1 : x);
}
}
```