18. Power of 2
My Approach
With example
- Input: n = 8
- Binary representation of 8 = (1000)
- Binary representation of (8 - 1) = 7 = (0111)
- Bitwise AND of 8 and 7 = (1000 & 0111), which is (0000).
- Since the result is 0, we can conclude that 8 is a power of two.Time and Auxiliary Space Complexity
Code (C++)
Contribution and Support
Last updated