Power of Two

Given an integer n, return true if it is a power of two. Pattern focus: Isolate Lowest Bit. A power of two has exactly one set bit, so isolating the lowest set bit is a natural test.

Input Format

n = integer

Output Format

true if n is a power of two

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9
  • n must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

n = 16

Output:

true

Explanation:

16 is 2^4 and has exactly one set bit.

Example 2:

Input:

n = 3

Output:

false

Explanation:

3 is 11 in binary and has two set bits.

Loading...
Power of Two - Bit Manipulation DSA Problem