One line solution in Javascript


  • 1
    B

    Initially, i tried the commented out code, but I would receive 4.99999999 for 243, so I tried a new approach seeing what the Max safe number is in javascript using Number.MAX_SAFE_INTEGER to figure what was the highest power I can use.

      var isPowerOfThree = function(n) {
        // return n !== 0 && (Math.log(n) / Math.log(3)) % 1 === 0;
        return n > 0 && Math.pow(3,33) % n === 0;
    };
    

Log in to reply
 

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