C++ ugly corner case


  • 0
    J
    class Solution {
    public:
        double myPow(double x, int n) {
            int sign =1;
            if(n==INT_MIN)
            {
                return abs(x)==1.0?1.0:0.0;
            }
            if(n<0) sign = -1;
            n = abs(n);
            if(n==0) return 1;
            if(n%2==0) 
            {
                double res = myPow(x,n/2);
                double result = res*res;
                return sign==1?result:1/result;
            }
            else
            {
                double res = myPow(x,n/2);
                double  result = res*res*x;
                return sign==1?result:1/result;
            }
                
        }
    };
    

  • 0
    J
    This post is deleted!

Log in to reply
 

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