标签:new power turn return color div double 次方 ase
给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。
public class Solution { public double Power(double base, int exponent) { if(exponent == 0)return 1; if(exponent == 1)return base; boolean flag = false; if(exponent < 0) { exponent = -exponent; flag = true; } double pow = Power(base * base, exponent/2); if(exponent/2 == 1) { pow = pow * base; } return flag == true?1/pow:pow; } }
标签:new power turn return color div double 次方 ase
原文地址:https://www.cnblogs.com/yihangZhou/p/10447871.html