dsa · easy
Power of Two
Return whether n is a positive power of two (1, 2, 4, 8, …).
Arguments
n— integer to test
Example
n = 16 → true. n = 3 → false. n = 1 → true.
Constraints
-2^31 <= n <= 2^31 - 1 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: 1 Expected: true
Example 2
Input: 16 Expected: true
Example 3
Input: 3 Expected: false