Getting Wrong Answer when x is 2 and n is -2147483648


  • 0
    G

    double myPow(double x, int n) {

    if(n==0)
        return 1.0;
    if(n<0)
        {
            y = 1/x;
            n = -n;
        }
    double temp = myPow(y,n/2);
        return (n%2==1?temp*temp*y:temp*temp);
    

    }
    // when n is = -2147483648 then -n is also the same.How to deal with this case?


  • -1
    S

    for n = INT_MIN, do x = 1/x; x = xx; n = n + 1 ; n = -1n;


Log in to reply
 

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