The problem. Given an integer n, return true if it's a power of two — n == 2ˣ for some integer x ≥ 0 — and false otherwise.
n = 1 -> true (2^0)
n = 16 -> true (2^4)
n = 12 -> false
n = 0 -> false
n = -8 -> falseMembers only · free account
The rest of this lesson, with 7 more sections, 1 drawing, a dry-run simulator and code in JavaScript, Python, Java and C++, opens with a free account.
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson