naive C solution


  • 0
    bool isPowerOfThree(int n) {
        int power;
        double log3 = log(3);
        if(n==0 ) return false;
        power = (int)(log(n)/log3 + 0.5);
        if(pow(3,power) == n) return true;
        else return false;
    }

Log in to reply
 

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