@@ -0,0 +1,1244 @@
+/**%0A *%09Implement pow(x, n).%0A *%0A *%09Author: matao%0A */%0A%0Apublic class Power %7B%0A%09public static double myPow(double x, long n) %7B%0A        if(equal(x, 0.0) && n %3C 0) %7B%0A            return Double.POSITIVE_INFINITY;%0A        %7D%0A        int sign = 1;%0A        if(n %3C 0) %7B%0A            sign = -1;%0A            n = -n;%0A        %7D%0A        double result = myPowHelper(x, n);%0A        if(sign == -1) %7B%0A            result = 1.0 / result;%0A        %7D%0A        return result;%0A    %7D%0A    %0A    public static double myPowHelper(double x, long n) %7B%0A        if(n == 0) %7B%0A            return 1.0;%0A        %7D%0A        if(n == 1) %7B%0A            return x;%0A        %7D%0A        double result = myPowHelper(x, n %3E%3E 1);%0A        result *= result;%0A        if((n & 1) == 1) %7B%0A            result *= x;%0A        %7D%0A        return result;%0A    %7D%0A    %0A    public static boolean equal(double num1, double num2) %7B%0A        double tmp = num1 - num2;%0A        if(tmp %3C 0.000001 && tmp %3E -0.000001) %7B%0A            return true;%0A        %7D%0A        return false;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A    %09System.out.println(myPow(10, 2));%0A    %09System.out.println(myPow(10, -2));%0A    %09System.out.println(myPow(10, 0));%0A    %09System.out.println(myPow(0, 0));%0A    %09System.out.println(myPow(0, -1));%0A    %7D%0A%7D

add power solution