LeetCode 326. Power of Three

判斷一數是否為三的次方數

/**
* @param {number} n
* @return {boolean}
*/
var isPowerOfThree = function(n) {
return (n > 0 && Math.log10(n) / Math.log10(3) % 1 === 0)
};

如果n是3的x次方,那麼以3為底的對数一定是整數

Like what you read? Give Wei zen Liu a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.