Skip to main content
Easy Bit Manipulation Medium frequency

Power of Two

Open on LeetCode

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

This site is free. If these guides are helping your prep, consider buying me a coffee. ☕

Support →
Buy me a coffee