class Solution {
public static double myPow(double x, int n) {
long N = n;
if(N<0){
N = -N;
x = 1.0D/x;
}
double ans = 1d;
while(true){
if(N==0){
break;
}
if((N&1)==1){
ans*=x;
}
N>>=1;
x*=x;
}
return ans;
}
}
leetcode Pow(x,n)
最新推荐文章于 2024-08-08 16:55:45 发布