Power of Two

Easy

Given an integer n, return true if it is a power of two. Otherwise return false.

Example 1

isPowerOfTwo()
Input
n = 1
Output
true

Why

2⁰ = 1

Example 2

isPowerOfTwo()
Input
n = 3
Output
false
Constraints
-2^31 <= n <= 2^31 - 1

Topics

MathBit Manipulation

Implement isPowerOfTwo in the editor and return the answer — printing it is never graded.