Power of Two

EasyBit Manipulation

Description

Given an integer n, return true if it is a power of two. Otherwise, return false. An integer n is a power of two, if there exists an integer x such that n == 2^x.

Examples

Input:n = 1
Output:true
Explanation:

1 = 2^0, which is a valid power of two. In binary, 1 is represented as '1' with exactly one bit set.

Input:n = 16
Output:true
Explanation:

16 = 2^4. In binary, 16 is '10000' with exactly one bit set. Powers of two always have exactly one '1' bit.

Input:n = 3
Output:false
Explanation:

3 in binary is '11' which has two bits set. Powers of two have exactly one bit set, so 3 is not a power of 2.

Constraints

  • -2³¹ ≤ n ≤ 2³¹ - 1

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!