Implement pow(x, n).
1 public class Solution { 2 public double myPow(double x, int n) { 3 if(n==0) return 1; 4 if(n<0){ 5 if(n==Integer.MIN_VALUE){ 6 x = 1/x; 7 n = n+1; 8 n = -n; 9 return x*x*myPow(x*x,n/2); 10 } 11 x = 1/x; 12 n = -n; 13 } 14 return n%2==0?myPow(x*x,n/2):x*myPow(x*x,n/2); 15 } 16 }