题解 | #数值的整数次方#
数值的整数次方
https://www.nowcoder.com/practice/1a834e5e3e1a4b7ba251417554e07c00
class Solution { public: double Power(double base, int exponent) { if(exponent == 0) return 1; if(base == 0) return 0; double ret = 1; int e = exponent < 0 ? -exponent : exponent; while(e) { ret *= base; e--; } if(exponent < 0) return 1/ret; else return ret; } };