Approach Summary
a ^ b gives sum without carry; (a & b) << 1 gives carry. Repeat until carry = 0.
How to Recognize This Pattern
- "Add without + or -"
- XOR = addition without carry; AND<<1 = carry bits
Complexity Analysis
Time Complexity
O(1)
Space Complexity
O(1)
Tags
Math Bit Manipulation