public class Solution {
public double myPow(double x, int n) {
if(x == 1){
return 1;
}else if(x == -1){
if(n%2 == 0)
return 1;
else
return -1;
}
if(n==0)
return 1.00;
if(n<0)
return 1.0/myPow(x,-n);
double half = myPow(x,n>>1);
if(n%2==0)
return half*half;
else
return half*half*x;
}
}
public double myPow(double x, int n) {
if(x == 1){
return 1;
}else if(x == -1){
if(n%2 == 0)
return 1;
else
return -1;
}
if(n==0)
return 1.00;
if(n<0)
return 1.0/myPow(x,-n);
double half = myPow(x,n>>1);
if(n%2==0)
return half*half;
else
return half*half*x;
}
}