MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/medium/_0050/Solution.java:11–29  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/10/18 desc :

Source from the content-addressed store, hash-verified

9 * </pre>
10 */
11public class Solution {
12 public double myPow(double x, int n) {
13 if (n < 0) return helper(1 / x, -n);
14 return helper(x, n);
15 }
16
17 private double helper(double x, int n) {
18 if (n == 0) return 1;
19 if (n == 1) return x;
20 double d = helper(x, n >>> 1);
21 if (n % 2 == 0) return d * d;
22 return d * d * x;
23 }
24
25 public static void main(String[] args) {
26 Solution solution = new Solution();
27 System.out.println(solution.myPow(8.88023, 3));
28 }
29}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected