Implement pow(x, n).
some consideration:
- what if n < 0
- avoid recompute
class Solution {
public:
double myPow(double x, int n) {
if(0 == n) return 1;
else if(1 == n) return x;
else if(-1 == n) return 1 / x;
else{
double t = myPow(x, n/2);
if(n % 2 == 0) return t * t;
else{
if(n > 0)return t * t * x;
else return t * t / x;
}
}
}
};