Power of Two
Return True if n can be written as 2 raised to some whole number power (1, 2, 4, 8, ...), otherwise False. Zero and negative numbers are not powers of two.
Example 1
n 16
returns true
2 to the 4th.
Example 2
n 12
returns false
Not a power of two.
Constraints
-231 <= n <= 231 - 1
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Product Minus Sum of DigitsBeginner
- Seconds to ClockBeginner
- Staircase of StonesBeginner
- Steps to Reduce to ZeroBeginner
- Sum of Consecutive PowersBeginner
- Sum of DivisorsBeginner
- Sum of MultiplesBeginner
- Type of TriangleBeginner