Sponsored Reserved space — layout preview until AdSense is connected
easy +8 pts

Power of two?

Bit math in one expression.

Implement `is_power_of_two(n: int) -> bool`. Return True if n > 0 and n is a power of 2.

Constraints

0 ≤ n ≤ 10^18

Example

>>> is_power_of_two(16)
True
>>> is_power_of_two(6)
False
8 points ~8 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

n & (n-1) == 0 is the classic trick (and n > 0).
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.
Sponsored Reserved space — layout preview until AdSense is connected