1 class Solution { 2 public: 3 double Power(double base, int exponent) { 4 bool posit = (exponent > 0) ? true : false; 5 exponent = posit ? exponent : (-exponent); 6 if(!exponent){ 7 return 1; 8 } 9 double tmp = base; 10 for(int i=1;i<exponent;++i){ 11 tmp *= base; 12 } 13 if(posit){ 14 return tmp; 15 } 16 else{ 17 return 1/tmp; 18 } 19 } 20 };