直接循环累乘
数值的整数次方
http://www.nowcoder.com/questionTerminal/1a834e5e3e1a4b7ba251417554e07c00
思路就是暴力累乘:
public class Solution { public double Power(double base, int exponent) { if (base == 0.0) { return base; } double sum = 1.0d; int n = exponent > 0 ? exponent : -exponent; while (n > 0) { sum = sum * base; n = n - 1; } return exponent > 0 ? sum : 1 / sum; } }