Java Solution without hardcoding or recursion

  • 0
    public boolean isPowerOfThree(int n) {
                 //this calculates log(n) to the base 3 == log(n)/log(3)
                double numerator = Math.log(n);
                double denom = Math.log(3);
                int value = (int) Math.round(numerator/denom);
               //raise the result of log to 3 and it should equal n
                    return true;
            return false;

Log in to reply

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