Reverse Bits
LeetCode 190 • Easy • Bit manipulation
Reverse bits of unsigned 32-bit integer n. Shift result left, pull lowest bit from n, shift n right — repeat 32 times.
TimeO(32)
SpaceO(1)
Step0/0
Ready
Each iteration: res = (res << 1) | (n & 1), then n >>= 1.