author: Blankj blog : http://blankj.com time : 2017/10/18 desc :
| 9 | * </pre> |
| 10 | */ |
| 11 | public 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected