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

Oct 9, 2022

Iterate

Previous Post

LeetCode: Word Pattern

Oct 4, 2022

2 hash tables

HoningJS

Search Posts