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 = 1Output:
trueExplanation:
1 = 2^0, which is a valid power of two. In binary, 1 is represented as '1' with exactly one bit set.
Input:
n = 16Output:
trueExplanation:
16 = 2^4. In binary, 16 is '10000' with exactly one bit set. Powers of two always have exactly one '1' bit.
Input:
n = 3Output:
falseExplanation:
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