LeetCode: Power of Four Solution

School math

Approach

Change base

Implementation

1var isPowerOfFour = function (n) {
2 const getBaseLog = (x, y) => Math.log(y) / Math.log(x)
3
4 return Number.isInteger(getBaseLog(4, n))
5}

References

Original problem

Change of base (Wikipedia)

Math.log() (MDN)

Logarithm change of base rule (Khan Academy)

Math is not fun

Similar problems

Power of Two

Power of Three

Comments

Loading comments...

Tags

leetcode

math

Next Post

LeetCode: Number of Common Factors

Iterate

Previous Post

HoningJS

Search Posts