标签:str base lse == ase exp int solution block
数值的整数次方
题目描述
给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。
主要是考虑各种情况,
题外话, 今天心态微崩, 看个电影调节一下, 目前此题一个版本, 考虑不全
class Solution {
public:
double Power(double base, int exponent) {
double res = 1;
if (0 > exponent) {
base = 1.0 / base;
exponent = -exponent;
for (int i = 0; i < exponent; i++) {
res = res * base;
}
return res;
}
else if (0 == exponent) {
return res;
}
else {
for (int i = 0; i < exponent; i++) {
res = res * base;
}
return res;
}
}
};
标签:str base lse == ase exp int solution block
原文地址:https://www.cnblogs.com/hesper/p/10428718.html