How is this so easy? C++solution-did I do this in the right way?

  • 5
    class Solution {
        double myPow(double x, int n) {
            if(n==0||x==1) return 1;
            if(n==-2147483648) return (double)1/(x*myPow(x,2147483647));
            if(n<0) return (double)1/myPow(x,0-n);
            if(n%2==0) return myPow(x*x,n/2);
            return x* myPow(x,n-1);

  • -2
    This post is deleted!

Log in to reply

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