Leetcode Problem 231. Power of Two
231. Power of Two
AI Mock Interview
Leetcode Solutions
Bitwise AND of Number and Number Minus One
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Check if
n
is less than or equal to 0. If it is, return
false
because negative numbers and zero cannot be powers of two.
Perform a bitwise AND operation between
n
and
n - 1
.
If the result of the AND operation is 0, return
true
, indicating that
n
is a power of two.
If the result is not 0, return
false
, indicating that
n
is not a power of two.
Bitwise AND of Number and Negative Number
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...