LeetCode: Power of Two Solution

Secondary or high school math, I don't remember

Approach

Check if log2 of n is an integer. More in References section

Implementation

1var isPowerOfTwo = function (n) {
2 return Number.isInteger(Math.log2(n))
3}

References

Original problem

MDN Math.log()

Wikipedia List of logarithmic identities

Comments

Loading comments...

Tags

leetcode

math

Next Post

LeetCode: Rotting Oranges

Simultaneously spread from rotten cells

Previous Post

LeetCode: 01 Matrix

Speading from 0s

HoningJS

Search Posts