Back to problems Sign in to unlock
Leetcode
Easy
Bit Manipulation
Math
Power Of Two
Determine whether an integer is an exact power of two.
Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement
Given an integer n, return whether it can be written in the form 2^k for some integer k >= 0.
A number is a power of two if it is positive and has exactly one set bit in its binary representation.
Input Format
- A single integer
n. - Decide whether
nis a power of two.
Output Format
- Return
trueifnis an exact power of two. - Otherwise return
false.
Constraints
- You may assume
nfits in a standard 32-bit signed integer. nmay be non-positive.- Aim for or time.
Examples
Sample cases returned by the problem API.
Example 1
Input
n = 1
Output
true
Explanation
.
Example 2
Input
n = 16
Output
true
Explanation
.
Show 1 more example
Example 3
Input
n = 3
Output
false
Explanation
3 is not an exact power of two.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.