Power of Two
Easy
Math
Math
Bit Manipulation
Given an integer n, return true if n is a power of two, otherwise false.
Constraints
-2^31 ≤ n ≤ 2^31 - 1
Examples
Example 1:
Input: 1
Output: true
Example 2:
Input: 16
Output: true
Hints
n & (n-1) == 0 for powers of 2.
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console