Math Fundamentals18 sections · 814 units
Open in Course

Problem - Power of Two Check

LeetCode 231

Given a positive integer nn, determine if it is a power of two. A number is a power of two if n=2kn = 2^k for some non-negative integer kk.

For example, 1,2,4,8,161, 2, 4, 8, 16 are powers of two. But 3,5,6,73, 5, 6, 7 are not.

Before reading the solution, think: how can you use division and modulo to check this? What pattern do powers of two follow?