[LeetCode] 50. Pow(x, n)
package leetcode; /** * @author doyinana * @create 2020-05-11 22:33 */ public class L50 { public double quickMul(double x, long N) { if (N == 0) { return 1.0; } double y = quickMul(x, N / 2); return N % 2 == 0 ? y * y : y * y * x; } public double myPow(double x, int n) { long N = n; return N >= 0 ? quickMul(x, N) : 1.0 / quickMul(x, -N); } }