Solution that actually works - all test cases pass

  • 0
    class Solution {
        public double myPow(double x, int n) {
            long nn = n;
            return myPow(x,nn);
        private double myPow(double x, long n) {
            if(n==0) return 1;
                n = -n;
                x = 1/x;
            return n%2==0 ? myPow(x*x, n/2) : x*myPow(x*x, n/2);

  • 0

    What's up with the silly title? You make it sound like most/all solutions don't work...

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.