LeetCode 231: Power of Two (Bit Trick O(1) ACERS Guide)
Subtitle / Summary A classic bit-manipulation template: determine if a number is a power of two in O(1). This ACERS guide covers the core insight, practical uses, and runnable multi-language implementations. Reading time: 8–12 min Tags: bit manipulation, binary, math SEO keywords: Power of Two, bit manipulation, binary, O(1), LeetCode 231 Meta description: O(1) power-of-two check using bit tricks, with engineering scenarios and multi-language code. Target Readers LeetCode learners building a bit-manipulation toolkit Backend / systems engineers who need alignment or capacity checks Anyone who wants stable O(1) integer tests Background / Motivation Power-of-two checks show up everywhere: hash table capacities, memory alignment, sharding, FFT window sizes. Looping or using floating-point logs is slower and prone to corner-case bugs. The bitwise method is fast, simple, and reliable. ...