Pow(x, n)(C++) By yangchaojie


  • 0
    Y

    class Solution {
    public:
    double myPow(double x, int n) {
    double pow_x = 1.00000;
    if (n == 0)
    return 1.0;
    double half = pow(x, n/2);
    if (n%2 == 0)
    {
    return halfhalf;
    }
    else if (n>0)
    {
    return half
    halfx;
    }
    else
    {
    return half/x
    half;
    }

        //return pow_x;
    }
    

    };


Log in to reply
 

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