class Solution {
public:
double myPow(double x, int n) {
if (n == 0) {
return 1;
}
double half = myPow(x, n / 2);
//n is an even and postitive number
if (n % 2 == 0) {
return half * half;
}
//n is a positive number
if (n > 0) {
return half * half * x;
}
//n is a negative number
return half * half / x;
}
};