PIXELBANKv8.2.1
Menu

Power of Two

Given an integer n, return True if it is a power of two.

Example:

Input:
16
Output:
True
Reasoning:
  • The input 16 is analyzed to determine if it is a power of two.
  • We can express 16 as 242^4, which means it can be represented as a power of two.
  • To verify this, we can use the property that all powers of two have exactly one bit set to 1 in their binary representation: 16 in binary is 10000, which meets this condition.
  • Since 16 satisfies the condition of being a power of two, the function returns True.

Constraints:

  • -2^31 <= n <= 2^31 - 1
Editor

Test Results

0/0
Run code to see test results.