LeetCode 371 ·
Medium
Sum of Two Integers
Compute a + b without using the + or − operators.
Try it
Step through the core mechanic. The simulator below runs the bit manipulation shape this problem is built on.
Walk the pattern
No dedicated step-through for this one yet. The shape is Bit manipulation — its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.
The approach
XOR gives the sum without carries; AND shifted left gives the carries. Loop, folding the carry back in, until no carry remains — emulating a ripple-carry adder.
| Aspect | Value |
|---|---|
| Pattern | Bit manipulation |
| Recognise it by | Add without + or −. |
| Time complexity | O(1) |
| Space complexity | O(1) |
| Difficulty | Medium |
Who asks it
Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.