Power of Two
Power of Two
Given an integer n, return true if it is a power of two. Otherwise return false.
A power of two has exactly one bit set in its binary representation.
Function signature
func IsPowerOfTwo(n int) bool
Example
n = 16
output = true
Constraints
- -1_000_000_000 <= n <= 1_000_000_000
Notes
1is a power of two.0and negative numbers are not powers of two.
Run tests to see results
No issues detected