题目描述
给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。
class Solution {public:double Power(double base, int exponent) {double res = 1.0;for(int i = exponent; i != 0; i /= 2){if(i % 2 != 0)res *= base;base *= base;}return exponent < 0 ? 1 / res : res;}
};