Approach Summary
A power of two in binary has exactly one 1-bit. Check: n > 0 && (n & (n-1)) == 0.
How to Recognize This Pattern
- Powers of two have a single set bit
- n & (n-1) clears the lowest set bit — result should be 0
Complexity Analysis
Time Complexity
O(1)
Space Complexity
O(1)
Tags
Math Bit Manipulation Recursion