My Pow function


  • 0
    R

    My code gives timeout error .So,pls give any solutions..............
    This is my code....
    double myPow(double x, int n) {
    double ans=1;

    if(n<0){
        n=n*(-1);
        x=1/x;
    }
    while(n){
        if(n & 1)
            ans*=x;
        x=x*x;
        n=n>>1;
    }        
    return ans;
    

    }


Log in to reply
 

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