| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/feixiangcode/algorithm/master/Week_01/id_1/LeetCode_50_1.java | [Back] [Original] |
public class Solution {
double myPow(double x, int n) {
double result = this.pow(x, Math.abs(n));
if (n < 0) {
return 1/result;
}
return result;
}
private double pow(double x, int n) {
if (n == 0) {
return 1;
}
double half = pow(x, n / 2);
if (n % 2 == 0) {
return half * half;
} else {
return half * half * x;
}
}
}
| Web Proxy Viewer | New URL | Original Page |