```
public class Solution {
public double pow(double x, int n) {
return n > 0 ? power(x, n) : 1 / power(x, -n);
}
double power(double x, int n) {
if (n == 1) return x;
if (n == 0) return 1.0;
double tmp = power(x, n / 2);
return n % 2 == 0 ? tmp * tmp : tmp * tmp * x;
}
}
```