📘
Power of Two
Given an integer n, return True if it is a power of two.
Example:
Input:
16
Output:
True
Reasoning:
- The input
16is analyzed to determine if it is a power of two. - We can express
16as 24, 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
1in their binary representation:16in binary is10000, which meets this condition. - Since
16satisfies the condition of being a power of two, the function returnsTrue.
Constraints:
- -2^31 <= n <= 2^31 - 1
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.