Check Power of Two
Given a non-negative integer n, return true if there is an integer x such that n = 2^x; otherwise return false. By definition, 1 = 2^0 is a power of two,…
Given a non-negative integer `n`, return `true` if there is an integer `x` such that `n = 2^x`; otherwise return `false`. By definition, `1 = 2^0` is a power of two, while `0` is not.
- `0 ≤ n ≤ 10^9` - `n` is an integer. - The interactive visualizer accepts `0 ≤ n ≤ 10^6`; larger valid judge inputs remain execution-only.
Example 1: input n = 16; output true. 16 = 2^4.
Example 2: input n = 18; output false. No non-negative integer exponent produces 18.
Example 3: input n = 1; output true. 1 = 2^0.
Category: Math. Topic: math. Difficulty: Easy. Patterns: bit-manipulation.