231. Power of Two
Practice Power of Two for free on NudgeCode: Easy, Bit Manipulation pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Return true if the signed 32-bit integer n equals 2^k for some integer k >= 0, and false otherwise. Zero and negative numbers are never powers of two.
Example
n = 1 -> true (2^0)
n = 16 -> true (2^4)
n = 6 -> false
n = -16 -> false
Constraints
- -2^31 <= n <= 2^31 - 1