Implement pow(x, n).
class Solution {
public:
double pow(double x, int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(n==0) return 1;
if(n==1) return x;
bool sign = (n>0)?true:false;
n = abs(n);
double temp = x;
double result = 1;
while(n>0)
{
if(n&1==1) result *= temp; //重要,不是乘上x,而是乘上temp
temp *= temp;
n = n>>1;
}
return (sign)?result:(1.0/result);
}
};