题解 | #数值的整数次方#
数值的整数次方
https://www.nowcoder.com/practice/1a834e5e3e1a4b7ba251417554e07c00
import java.util.*; public class Solution { private double Pow(double x,int y){ double res=1; //快速幂 while(y!=0){ //y不是双数 if((y&1)!=0){ res*=x; } x*=x; y=y>>1; } return res; } public double Power(double base, int exponent) { if(exponent<0){ base=1/base; exponent=-exponent; } return Pow(base,exponent); } }