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

Sep 25, 2021

Simultaneously spread from rotten cells

Previous Post

LeetCode: 01 Matrix

Sep 24, 2021

Speading from 0s

HoningJS

Search Posts