power of three

we need return true if n is power of three n == 3^x;
he output wrong answer whre n is 243 i dont know why whole my code is correct

class Solution {
public:
    double x;
    bool isPowerOfThree(int n) 
    {
        if (n > 0)
        {
            x = log(n)/log(3);
            if (x == ceil(x))
                return true;
            else
                return false;
        }
        else
            return false;
    }
};
Comments (0)