C++代码:
class Solution { public: double Power(double base, int exponent) { if (!base && !exponent) return false; //保证不同时为0,base = 0,exponent = 0,无意义 if (!base && exponent < 0) return false; //base = 0,exponent <0,无意义 double res = 1; for(int i = 0; i < abs(exponent);i++) res *= base; if (exponent < 0) res = 1/res; return res; } };